Class: Reacter::Adapter
- Inherits:
-
Object
- Object
- Reacter::Adapter
- Defined in:
- lib/reacter/adapter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#enable ⇒ Object
readonly
Returns the value of attribute enable.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#connect(args = {}) ⇒ Object
implement: connect to the data source.
- #disable ⇒ Object
-
#disconnect ⇒ Object
implement: manual disconnect / cleanup.
- #enabled? ⇒ Boolean
-
#initialize(config = nil) ⇒ Adapter
constructor
A new instance of Adapter.
-
#poll(&block) ⇒ Object
implement: poll for a new message and return it.
-
#send(message, format = nil) ⇒ Object
implement: send a message suitable for consumption by an instance of reacter in listen mode.
Constructor Details
#initialize(config = nil) ⇒ Adapter
Returns a new instance of Adapter.
22 23 24 25 26 27 |
# File 'lib/reacter/adapter.rb', line 22 def initialize(config=nil) @config = (config || Reacter.get('global.adapter', {})) @type = @config.get('type') @enable = true Util.info("Loading adapter #{@type}...") end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
18 19 20 |
# File 'lib/reacter/adapter.rb', line 18 def config @config end |
#enable ⇒ Object (readonly)
Returns the value of attribute enable.
20 21 22 |
# File 'lib/reacter/adapter.rb', line 20 def enable @enable end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
19 20 21 |
# File 'lib/reacter/adapter.rb', line 19 def type @type end |
Class Method Details
.create(type, config = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/reacter/adapter.rb', line 63 def create(type, config=nil) if type begin require "reacter/adapters/#{type}" rv = (Reacter.const_get("#{type.capitalize}Adapter").new(config)) return rv rescue LoadError => e STDERR.puts("#{e.class.name}: #{e.message}") end end nil end |
Instance Method Details
#connect(args = {}) ⇒ Object
implement: connect to the data source
30 31 32 |
# File 'lib/reacter/adapter.rb', line 30 def connect(args={}) false end |
#disable ⇒ Object
50 51 52 |
# File 'lib/reacter/adapter.rb', line 50 def disable() @enable = false end |
#disconnect ⇒ Object
implement: manual disconnect / cleanup
46 47 48 |
# File 'lib/reacter/adapter.rb', line 46 def disconnect() @_connected = false end |
#enabled? ⇒ Boolean
58 59 60 |
# File 'lib/reacter/adapter.rb', line 58 def enabled?() @enable end |
#poll(&block) ⇒ Object
implement: poll for a new message and return it
41 42 43 |
# File 'lib/reacter/adapter.rb', line 41 def poll(&block) false end |
#send(message, format = nil) ⇒ Object
implement: send a message suitable for consumption by an instance of reacter
in listen mode
36 37 38 |
# File 'lib/reacter/adapter.rb', line 36 def send(, format=nil) raise "Send not implemented" end |