Module: Basquiat::Base
- Defined in:
- lib/basquiat/interfaces/base.rb
Overview
Base module used to extend the classes so that they will be able to use the event infrastructure
Instance Attribute Summary collapse
-
#adapter ⇒ Basquiat::Adapter
deprecated
Deprecated.
event_adapter is deprecated and will be removed eventually. Please use #adapter.
Class Method Summary collapse
Instance Method Summary collapse
- #adapter_options(opts = Basquiat.configuration.adapter_options) ⇒ Object
-
#connected? ⇒ truthy, falsey
Utility method to check connection status.
-
#disconnect ⇒ Object
Utility method to force a disconnect from the message queue.
-
#listen(block: true, rescue_proc: Basquiat.configuration.rescue_proc) ⇒ Object
Starts the consumer loop.
-
#publish(event, message) ⇒ Object
Publishes the message of type event to the queue.
- #reload_adapter_from_configuration ⇒ Object
-
#subscribe_to(event_name, proc) ⇒ Object
Subscribe the event with the proc passed.
Instance Attribute Details
#adapter ⇒ Basquiat::Adapter
event_adapter is deprecated and will be removed eventually. Please use #adapter.
Initializes and return a instance of the default adapter specified on Basquiat.configuration.default_adapter
32 33 34 |
# File 'lib/basquiat/interfaces/base.rb', line 32 def adapter=(adapter_klass) @adapter = @procs ? adapter_klass.new(procs: @procs) : adapter_klass.new end |
Class Method Details
.descendants ⇒ Object
13 14 15 |
# File 'lib/basquiat/interfaces/base.rb', line 13 def descendants @descendants ||= [] end |
.extended(klass) ⇒ Object
9 10 11 |
# File 'lib/basquiat/interfaces/base.rb', line 9 def extended(klass) descendants.push klass end |
.reconfigure_children ⇒ Object
17 18 19 |
# File 'lib/basquiat/interfaces/base.rb', line 17 def reconfigure_children descendants.each(&:reload_adapter_from_configuration) end |
Instance Method Details
#adapter_options(opts = Basquiat.configuration.adapter_options) ⇒ Object
43 44 45 |
# File 'lib/basquiat/interfaces/base.rb', line 43 def (opts = Basquiat.configuration.) adapter.(opts) end |
#connected? ⇒ truthy, falsey
Utility method to check connection status
72 73 74 |
# File 'lib/basquiat/interfaces/base.rb', line 72 def connected? adapter.connected? end |
#disconnect ⇒ Object
The adapter should reconnect automatically.
Utility method to force a disconnect from the message queue.
66 67 68 |
# File 'lib/basquiat/interfaces/base.rb', line 66 def disconnect adapter.disconnect end |
#listen(block: true, rescue_proc: Basquiat.configuration.rescue_proc) ⇒ Object
Starts the consumer loop
79 80 81 |
# File 'lib/basquiat/interfaces/base.rb', line 79 def listen(block: true, rescue_proc: Basquiat.configuration.rescue_proc) adapter.listen(block: block, rescue_proc: rescue_proc) end |
#publish(event, message) ⇒ Object
Publishes the message of type event to the queue. Note that the message will be converted to a JSON
50 51 52 |
# File 'lib/basquiat/interfaces/base.rb', line 50 def publish(event, ) adapter.publish(event, ) end |
#reload_adapter_from_configuration ⇒ Object
22 23 24 25 26 |
# File 'lib/basquiat/interfaces/base.rb', line 22 def reload_adapter_from_configuration @procs = adapter.procs self.adapter = Kernel.const_get(Basquiat.configuration.default_adapter) Basquiat.configuration. end |
#subscribe_to(event_name, proc) ⇒ Object
Subscribe the event with the proc passed.
59 60 61 62 |
# File 'lib/basquiat/interfaces/base.rb', line 59 def subscribe_to(event_name, proc) proc = make_callable(proc) adapter.subscribe_to(event_name, proc) end |