Skip to content

Commit

Permalink
Refactor: inline cached_connection (#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleolleolle authored and iMacTia committed May 8, 2018
1 parent 1fa9051 commit 632ea6c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/faraday/adapter/net_http_persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ class NetHttpPersistent < NetHttp
private

def net_http_connection(env)
cached_connection do
@cached_connection ||=
if Net::HTTP::Persistent.instance_method(:initialize).parameters.first == [:key, :name]
Net::HTTP::Persistent.new(name: 'Faraday')
else
Net::HTTP::Persistent.new('Faraday')
end
end

proxy_uri = proxy_uri(env)
cached_connection.proxy = proxy_uri if cached_connection.proxy_uri != proxy_uri
cached_connection
@cached_connection.proxy = proxy_uri if @cached_connection.proxy_uri != proxy_uri
@cached_connection
end

def proxy_uri(env)
Expand Down Expand Up @@ -61,10 +61,6 @@ def http_set(http, attr, value)
http.send("#{attr}=", value)
end
end

def cached_connection
@cached_connection ||= yield
end
end
end
end

0 comments on commit 632ea6c

Please sign in to comment.