Class: Omnidata::Adapters::AdapterManager

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/omnidata/adapters/adapter_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAdapterManager

Returns a new instance of AdapterManager.



14
15
16
# File 'lib/omnidata/adapters/adapter_manager.rb', line 14

def initialize
  reset
end

Instance Attribute Details

#adaptersObject (readonly)

Returns the value of attribute adapters.



12
13
14
# File 'lib/omnidata/adapters/adapter_manager.rb', line 12

def adapters
  @adapters
end

Instance Method Details

#adapter(name) ⇒ Object



38
39
40
# File 'lib/omnidata/adapters/adapter_manager.rb', line 38

def adapter(name)
  @adapters[name]
end

#add(name, options) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/omnidata/adapters/adapter_manager.rb', line 22

def add(name, options)
  if adapter(name)
    raise AdapterError.new("adapter #{name} exists")
  end

  adapter = build_adapter(options)
  adapter.name = name
  @adapters[name] = adapter
end

#build_adapter(options) ⇒ Object



32
33
34
35
36
# File 'lib/omnidata/adapters/adapter_manager.rb', line 32

def build_adapter(options)
  opts = options.dup
  name = opts.delete(:adapter).capitalize
  "Omnidata::Adapters::#{name}Adapter".constantize.new(opts)
end

#resetObject



18
19
20
# File 'lib/omnidata/adapters/adapter_manager.rb', line 18

def reset
  @adapters = {}
end