Class: Faraday::AdapterRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/faraday/adapter_registry.rb

Overview

AdapterRegistry registers adapter class names so they can be looked up by a String or Symbol name.

Instance Method Summary collapse

Constructor Details

#initializeAdapterRegistry

Returns a new instance of AdapterRegistry.



9
10
11
12
# File 'lib/faraday/adapter_registry.rb', line 9

def initialize
  @lock = Monitor.new
  @constants = {}
end

Instance Method Details

#get(name) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/faraday/adapter_registry.rb', line 14

def get(name)
  klass = @lock.synchronize do
    @constants[name]
  end
  return klass if klass

  Object.const_get(name).tap { |c| set(c, name) }
end

#set(klass, name = nil) ⇒ Object



23
24
25
26
27
28
# File 'lib/faraday/adapter_registry.rb', line 23

def set(klass, name = nil)
  name ||= klass.to_s
  @lock.synchronize do
    @constants[name] = klass
  end
end