Class: Connectors::Factory
- Inherits:
-
Object
- Object
- Connectors::Factory
- Defined in:
- lib/connectors/registry.rb
Instance Attribute Summary collapse
-
#connectors ⇒ Object
readonly
Returns the value of attribute connectors.
Instance Method Summary collapse
- #connector(name, configuration) ⇒ Object
- #connector_class(name) ⇒ Object
-
#initialize ⇒ Factory
constructor
A new instance of Factory.
- #register(name, klass) ⇒ Object
- #registered?(name) ⇒ Boolean
- #registered_connectors ⇒ Object
Constructor Details
#initialize ⇒ Factory
Returns a new instance of Factory.
11 12 13 |
# File 'lib/connectors/registry.rb', line 11 def initialize @connectors = {} end |
Instance Attribute Details
#connectors ⇒ Object (readonly)
Returns the value of attribute connectors.
9 10 11 |
# File 'lib/connectors/registry.rb', line 9 def connectors @connectors end |
Instance Method Details
#connector(name, configuration) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/connectors/registry.rb', line 27 def connector(name, configuration) klass = connector_class(name) if klass.present? return klass.new(configuration: configuration) end raise "Connector #{name} is not yet registered. You need to register it before use" end |
#connector_class(name) ⇒ Object
23 24 25 |
# File 'lib/connectors/registry.rb', line 23 def connector_class(name) @connectors[name] end |
#register(name, klass) ⇒ Object
15 16 17 |
# File 'lib/connectors/registry.rb', line 15 def register(name, klass) @connectors[name] = klass end |
#registered?(name) ⇒ Boolean
19 20 21 |
# File 'lib/connectors/registry.rb', line 19 def registered?(name) @connectors.has_key?(name) end |
#registered_connectors ⇒ Object
35 36 37 |
# File 'lib/connectors/registry.rb', line 35 def registered_connectors @connectors.keys.sort end |