Skip to content

Commit

Permalink
rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ilackarms committed Aug 2, 2017
1 parent 6d46d6d commit 09c480e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
28 changes: 17 additions & 11 deletions lib/kubeclient/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ def handle_exception
rescue JSON::ParserError
{}
end
err_message = json_error_msg['message'] || e.message
error_klass = e.http_code == 404 ? ResourceNotFoundError : HttpError
raise error_klass.new((e.http_code || 404), err_message, e.response)
http_err(json_error_msg, e)
end

def discover
Expand Down Expand Up @@ -297,9 +295,7 @@ def get_entities(entity_type, klass, resource_name, options = {})
resource_version_streamer = Json::Streamer::JsonStreamer.new

resource_version_streamer.get(key: 'resourceVersion') do |value|
unless resource_version
resource_version = value
end
resource_version = value unless resource_version
end

entities = []
Expand All @@ -314,7 +310,11 @@ def get_entities(entity_type, klass, resource_name, options = {})
end

block = proc do |response|
raise ResourceNotFoundError.new(404, 'Not Found', response) if response.instance_of?(Net::HTTPNotFound)
if response.instance_of?(Net::HTTPNotFound)
raise ResourceNotFoundError.new(404,
'Not Found',
response)
end
response.read_body do |chunk|
entity_streamer.parser << chunk
end
Expand All @@ -325,10 +325,10 @@ def get_entities(entity_type, klass, resource_name, options = {})
block: block, method: :get, headers: @headers, params: params)
end

unless block_given?
collection = entities.to_a
Kubeclient::Common::EntityList.new(entity_type, resource_version, collection)
end
return if block_given?

collection = entities.to_a
Kubeclient::Common::EntityList.new(entity_type, resource_version, collection)
end

def get_entity(klass, resource_name, name, namespace = nil)
Expand Down Expand Up @@ -553,5 +553,11 @@ def http_options(uri)

options.merge(@socket_options)
end

def http_err(json_error_msg, e)
err_message = json_error_msg['message'] || e.message
error_klass = e.http_code == 404 ? ResourceNotFoundError : HttpError
raise error_klass.new((e.http_code || 404), err_message, e.response)
end
end
end
4 changes: 2 additions & 2 deletions test/test_kubeclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ def test_nonjson_exception

def test_entity_list_with_block
stub_request(:get, %r{/api/v1$})
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
stub_request(:get, %r{/services})
.to_return(body: open_test_file('entity_list.json'), status: 200)
.to_return(body: open_test_file('entity_list.json'), status: 200)

client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
services = []
Expand Down

0 comments on commit 09c480e

Please sign in to comment.