Class: Eql::AdapterFactory
- Inherits:
-
Object
- Object
- Eql::AdapterFactory
- Defined in:
- lib/eql/adapter_factory.rb
Overview
AdapterFactory class detects adapters and their helpers
Constant Summary collapse
- HELPERS_MODULE_NAME =
:ContextHelpers
Class Method Summary collapse
-
.adapter_helpers(adapter) ⇒ Array<Module>
Get adapter’s helper modules.
-
.adapters ⇒ Hash{Symbol => Eql::Adapters::Base}
Registered adapters.
-
.factory(conn) ⇒ Eql::Adapters::Base
Detect adapter class.
-
.register_adapter(key, klass) ⇒ Object
Register a new adapter.
Class Method Details
.adapter_helpers(adapter) ⇒ Array<Module>
Get adapter’s helper modules
36 37 38 39 40 41 42 |
# File 'lib/eql/adapter_factory.rb', line 36 def adapter_helpers(adapter) adapter.class.ancestors.each_with_object([]) do |klass, ret| next unless klass.is_a?(Class) next unless klass.const_defined?(HELPERS_MODULE_NAME) ret.unshift klass.const_get(HELPERS_MODULE_NAME) end end |
.adapters ⇒ Hash{Symbol => Eql::Adapters::Base}
Registered adapters
15 16 17 |
# File 'lib/eql/adapter_factory.rb', line 15 def adapters @adapters ||= {} end |
.factory(conn) ⇒ Eql::Adapters::Base
Detect adapter class
53 54 55 56 57 58 59 60 |
# File 'lib/eql/adapter_factory.rb', line 53 def factory(conn) return Eql.config.default_adapter unless conn adapter = adapters.values.find do |a| a.match?(conn) if a.is_a?(Class) && a.respond_to?(:match?) end raise "Unable to detect adapter for #{conn.inspect}" unless adapter adapter end |
.register_adapter(key, klass) ⇒ Object
Register a new adapter
25 26 27 |
# File 'lib/eql/adapter_factory.rb', line 25 def register_adapter(key, klass) adapters[key] = klass end |