Skip to content

Commit

Permalink
Refactoring unnecessarily nested if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
peteygee123 committed Jan 29, 2012
1 parent fdb8561 commit cb4a9c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
14 changes: 7 additions & 7 deletions lib/riak/client/net_http_backend.rb
Expand Up @@ -55,15 +55,15 @@ def perform(method, uri, headers, expect, data=nil) #:nodoc:

{}.tap do |result|
http.request(request) do |response|
if valid_response?(expect, response.code)
result.merge!({:headers => response.to_hash, :code => response.code.to_i})
response.read_body {|chunk| yield chunk } if block_given?
if return_body?(method, response.code, block_given?)
result[:body] = response.body
end
else
unless valid_response?(expect, response.code)
raise Riak::HTTPFailedRequest.new(method, expect, response.code.to_i, response.to_hash, response.body)
end

result.merge!({:headers => response.to_hash, :code => response.code.to_i})
response.read_body {|chunk| yield chunk } if block_given?
if return_body?(method, response.code, block_given?)
result[:body] = response.body
end
end
end
end
Expand Down
12 changes: 5 additions & 7 deletions lib/riak/link.rb
Expand Up @@ -53,14 +53,12 @@ def initialize(*args)

# @return [String] the URL (relative or absolute) of the related resource
def url(new_scheme=false)
if @bucket
if new_scheme
"/buckets/#{escape(bucket)}" + (key.blank? ? "" : "/keys/#{escape(key)}")
else
"/riak/#{escape(bucket)}" + (key.blank? ? "" : "/#{escape(key)}")
end
return @url unless @bucket

if new_scheme
"/buckets/#{escape(bucket)}" + (key.blank? ? "" : "/keys/#{escape(key)}")
else
@url
"/riak/#{escape(bucket)}" + (key.blank? ? "" : "/#{escape(key)}")
end
end

Expand Down
17 changes: 7 additions & 10 deletions lib/riak/node/console.rb
Expand Up @@ -34,16 +34,13 @@ def initialize(pipedir, nodename)
@prompt = /\(#{Regexp.escape(nodename)}\)\d+>\s*/
pipedir = Pathname(pipedir)
pipedir.children.each do |path|
if path.pipe?
if path.fnmatch("*.r") # Read pipe
# debug "Found read pipe: #{path}"
@rfile ||= path
elsif path.fnmatch("*.w") # Write pipe
# debug "Found write pipe: #{path}"
@wfile ||= path
end
else
debug "Non-pipe found! #{path}"
debug "Non-pipe found! #{path}" unless path.pipe?
if path.fnmatch("*.r") # Read pipe
# debug "Found read pipe: #{path}"
@rfile ||= path
elsif path.fnmatch("*.w") # Write pipe
# debug "Found write pipe: #{path}"
@wfile ||= path
end
end
raise ArgumentError, t('no_pipes', :path => pipedir.to_s) if [@rfile, @wfile].any? {|p| p.nil? }
Expand Down

0 comments on commit cb4a9c5

Please sign in to comment.