Permalink
Browse files

Refactoring unnecessarily nested if statements

  • Loading branch information...
1 parent fdb8561 commit cb4a9c5f57e1da4a06ef4f3f6086afeba3fb0333 Peter Garbers committed Jan 29, 2012
Showing with 19 additions and 24 deletions.
  1. +7 −7 lib/riak/client/net_http_backend.rb
  2. +5 −7 lib/riak/link.rb
  3. +7 −10 lib/riak/node/console.rb
@@ -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
View
@@ -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
View
@@ -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? }

0 comments on commit cb4a9c5

Please sign in to comment.