Class: Flexirest::ConnectionManager
- Inherits:
-
Object
- Object
- Flexirest::ConnectionManager
- Defined in:
- lib/flexirest/connection_manager.rb
Class Method Summary collapse
- .find_connection_for_url(url) ⇒ Object
- .get_connection(base_url) ⇒ Object
- .in_parallel(base_url) ⇒ Object
- .reset! ⇒ Object
Class Method Details
.find_connection_for_url(url) ⇒ Object
14 15 16 17 18 |
# File 'lib/flexirest/connection_manager.rb', line 14 def self.find_connection_for_url(url) Thread.current[:_connections] ||= {} found = Thread.current[:_connections].keys.detect {|key| url[0,key.length] == key} Thread.current[:_connections][found] if found end |
.get_connection(base_url) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/flexirest/connection_manager.rb', line 7 def self.get_connection(base_url) raise Exception.new("Nil base URL passed to ConnectionManager.get_connection") if base_url.nil? Thread.current[:_connections] ||= {} Thread.current[:_connections][base_url] ||= Connection.new(base_url) Thread.current[:_connections][base_url] end |
.in_parallel(base_url) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/flexirest/connection_manager.rb', line 20 def self.in_parallel(base_url) begin require 'typhoeus' require 'typhoeus/adapters/faraday' unless Gem.loaded_specs["faraday-typhoeus"].present? rescue LoadError raise MissingOptionalLibraryError.new("To call '::Flexirest::ConnectionManager.in_parallel' you must include the gem 'Typhoeus' in your Gemfile.") end session = ConnectionManager.get_connection(base_url).session session.in_parallel do yield if block_given? end end |
.reset! ⇒ Object
3 4 5 |
# File 'lib/flexirest/connection_manager.rb', line 3 def self.reset! Thread.current[:_connections]={} end |