Skip to content

Commit

Permalink
Fix some deprecations in Excon backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
seancribbs committed Apr 11, 2012
1 parent 8dd0918 commit acee3ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions lib/riak/client/excon_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.configured?
require 'excon'
Client::NETWORK_ERRORS << Excon::Errors::SocketError
Client::NETWORK_ERRORS.uniq!
Gem::Version.new(Excon::VERSION) >= Gem::Version.new("0.5.7") && patch_excon
minimum_version?("0.5.7") && patch_excon
rescue LoadError
false
end
Expand All @@ -34,6 +34,13 @@ def sockets
@@patched = true
end

# Returns true if the Excon library is at least the given
# version. This is used inside the backend to check how to
# provide certain request and configuration options.
def self.minimum_version?(version)
Gem::Version.new(Excon::VERSION) >= Gem::Version.new(version)
end

def teardown
connection.reset
end
Expand All @@ -54,7 +61,12 @@ def perform(method, uri, headers, expect, data=nil, &block)
# Later versions of Excon pass multiple arguments to the block
block = lambda {|*args| yield args.first } if block_given?

response = connection.request(params, &block)
if self.class.minimum_version?("0.10.2")
params[:response_block] = block if block
response = connection.request(params)
else
response = connection.request(params, &block)
end

This comment has been minimized.

Copy link
@myronmarston

myronmarston Apr 11, 2012

Contributor

So it looks like this will check the version on every single request, right? That's a bit wasteful since the version will never change between requests; once a version of excon is loaded, that's the version that will be used for the rest of that process's lifetime. For cases like these, I tend to define a helper method, and put the conditional at the class level:

private

if minimum_version?("0.10.2")
  def make_request(params, block)
    params[:response_block] = block if block
    connection.request(params)
  end
else
  def make_request(params, block)
    connection.request(params, &block)
  end
end

Then you can call make_request from the perform method, with no version conditional needed.

This comment has been minimized.

Copy link
@seancribbs

seancribbs Apr 11, 2012

Author Contributor

Good point, will fix.

response_headers.initialize_http_header(response.headers)

if valid_response?(expect, response.status)
Expand All @@ -73,8 +85,13 @@ def connection
end

def configure_ssl
Excon.ssl_verify_peer = @node.ssl_options[:verify_mode].to_s === "peer"
Excon.ssl_ca_path = @node.ssl_options[:ca_path] if @node.ssl_options[:ca_path]
if self.class.minimum_version?("0.9.6")
Excon.defaults[:ssl_verify_peer] = (@node.ssl_options[:verify_mode].to_s === "peer")
Excon.defaults[:ssl_ca_path] = @node.ssl_options[:ca_path] if @node.ssl_options[:ca_path]
else
Excon.ssl_verify_peer = @node.ssl_options[:verify_mode].to_s === "peer"
Excon.ssl_ca_path = @node.ssl_options[:ca_path] if @node.ssl_options[:ca_path]
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion riak-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "rspec", "~>2.8.0"
gem.add_development_dependency "fakeweb", ">=1.2"
gem.add_development_dependency "rack", ">=1.0"
gem.add_development_dependency "excon", "~>0.6.1"
gem.add_development_dependency "excon", ">=0.6.1"
gem.add_development_dependency 'rake'
gem.add_runtime_dependency "i18n", ">=0.4.0"
gem.add_runtime_dependency "builder", ">= 2.1.2"
Expand Down

0 comments on commit acee3ab

Please sign in to comment.