Class: Ductr::Adapter
- Inherits:
-
Object
- Object
- Ductr::Adapter
- Defined in:
- lib/ductr/adapter.rb
Overview
Base adapter class, your adapter should inherit of this class.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Hash<Symbol: Object>
readonly
The adapter configuration hash.
-
#name ⇒ Symbol
readonly
The adapter instance name.
Class Method Summary collapse
-
.destination_registry ⇒ Registry
All the destinations declared for this adapter goes here.
-
.lookup_registry ⇒ Registry
All the lookups declared for this adapter goes here.
-
.source_registry ⇒ Registry
All the sources declared for this adapter goes here.
-
.trigger_registry ⇒ Registry
All the triggers declared for this adapter goes here.
Instance Method Summary collapse
-
#close! ⇒ void
Closes the adapter when finished e.g.
-
#initialize(name, **config) ⇒ Adapter
constructor
Creates a new adapter instance.
-
#open { ... } ⇒ void
Allow use of adapter with block syntax, automatically closes on block exit.
-
#open! ⇒ void
Opens the adapter before using it e.g.
Constructor Details
#initialize(name, **config) ⇒ Adapter
Creates a new adapter instance.
58 59 60 61 |
# File 'lib/ductr/adapter.rb', line 58 def initialize(name, **config) @name = name @config = config end |
Instance Attribute Details
#config ⇒ Hash<Symbol: Object> (readonly)
Returns the adapter configuration hash.
50 51 52 |
# File 'lib/ductr/adapter.rb', line 50 def config @config end |
#name ⇒ Symbol (readonly)
Returns the adapter instance name.
47 48 49 |
# File 'lib/ductr/adapter.rb', line 47 def name @name end |
Class Method Details
.destination_registry ⇒ Registry
All the destinations declared for this adapter goes here.
32 33 34 |
# File 'lib/ductr/adapter.rb', line 32 def destination_registry @destination_registry ||= Registry.new(:destination) end |
.lookup_registry ⇒ Registry
All the lookups declared for this adapter goes here.
23 24 25 |
# File 'lib/ductr/adapter.rb', line 23 def lookup_registry @lookup_registry ||= Registry.new(:lookup) end |
Instance Method Details
#close! ⇒ void
This method returns an undefined value.
Closes the adapter when finished e.g. close connection, drop http session, close file…
90 91 92 |
# File 'lib/ductr/adapter.rb', line 90 def close! raise NotImplementedError, "An adapter must implement the #close! method" end |
#open { ... } ⇒ void
This method returns an undefined value.
Allow use of adapter with block syntax, automatically closes on block exit.
69 70 71 72 73 |
# File 'lib/ductr/adapter.rb', line 69 def open(&) yield(open!) ensure close! end |
#open! ⇒ void
This method returns an undefined value.
Opens the adapter before using it e.g. open connection, authenticate to http endpoint, open file… This method may return something, as a connection object.
81 82 83 |
# File 'lib/ductr/adapter.rb', line 81 def open! raise NotImplementedError, "An adapter must implement the #open! method" end |