Module: Flex::HttpClients::Loader

Extended by:
Loader
Included in:
Loader
Defined in:
lib/flex/http_clients/loader.rb

Instance Method Summary collapse

Instance Method Details

#new_http_clientObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/flex/http_clients/loader.rb', line 16

def new_http_client
  if Gem::Specification.respond_to?(:find_all_by_name)
    case
      # terrible way to check whether a gem is available.
      # Gem.available? was just perfect: that's probably the reason it has been deprecated!
      # https://github.com/rubygems/rubygems/issues/176
    when Gem::Specification::find_all_by_name('patron').any?      then require_patron
    when Gem::Specification::find_all_by_name('rest-client').any? then require_rest_client
    else Dummy.new
    end
  else
    case
    when Gem.available?('patron')      then require_patron
    when Gem.available?('rest-client') then require_rest_client
    else Dummy.new
    end
  end
end