Module: Rester::Client::Adapters
- Defined in:
- lib/rester/client/adapters.rb,
lib/rester/client/adapters/adapter.rb,
lib/rester/client/adapters/http_adapter.rb,
lib/rester/client/adapters/stub_adapter.rb,
lib/rester/client/adapters/local_adapter.rb,
lib/rester/client/adapters/http_adapter/connection.rb
Defined Under Namespace
Classes: Adapter, HttpAdapter, LocalAdapter, StubAdapter
Constant Summary collapse
- DEFAULT_OPTS =
Default connection options.
{ timeout: 10 # time in seconds (may be float) }.freeze
Class Method Summary collapse
-
.connect(service, opts = {}) ⇒ Object
Returns an instance of the appropriate adapter that is connected to the service.
-
.extract_opts(opts = {}) ⇒ Object
Given a hash, extracts the options that are part of the adapter interface.
-
.list ⇒ Object
Returns a list of available adapter classes.
Class Method Details
.connect(service, opts = {}) ⇒ Object
Returns an instance of the appropriate adapter that is connected to the service.
26 27 28 29 30 |
# File 'lib/rester/client/adapters.rb', line 26 def connect(service, opts={}) klass = list.find { |a| a.can_connect_to?(service) } fail "unable to connect to #{service.inspect}" unless klass klass.new(service, opts) end |
.extract_opts(opts = {}) ⇒ Object
Given a hash, extracts the options that are part of the adapter interface.
35 36 37 38 |
# File 'lib/rester/client/adapters.rb', line 35 def extract_opts(opts={}) sel = proc { |k, _| DEFAULT_OPTS.keys.include?(k) } DEFAULT_OPTS.merge(opts.select(&sel).tap { opts.delete_if(&sel) }) end |
.list ⇒ Object
Returns a list of available adapter classes.
18 19 20 21 |
# File 'lib/rester/client/adapters.rb', line 18 def list constants.map { |c| const_get(c) } .select { |c| c.is_a?(Class) && c < Adapter } end |