Class: RabbitmqClient::Lifecycle
- Inherits:
-
Object
- Object
- RabbitmqClient::Lifecycle
- Defined in:
- lib/rabbitmq_client/lifecycle.rb
Overview
Lifecycle defines the rabbitmq_client lifecycle events, callbacks and manage the execution of these callbacks
Constant Summary collapse
- EVENTS =
{ publish: %i[message options] }.freeze
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
Instance Method Summary collapse
- #after(event, &block) ⇒ Object
- #before(event, &block) ⇒ Object
-
#initialize ⇒ Lifecycle
constructor
A new instance of Lifecycle.
- #run_callbacks(event, *args, &block) ⇒ Object
Constructor Details
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
13 14 15 |
# File 'lib/rabbitmq_client/lifecycle.rb', line 13 def callbacks @callbacks end |
Instance Method Details
#after(event, &block) ⇒ Object
25 26 27 |
# File 'lib/rabbitmq_client/lifecycle.rb', line 25 def after(event, &block) add(:after, event, &block) end |
#before(event, &block) ⇒ Object
21 22 23 |
# File 'lib/rabbitmq_client/lifecycle.rb', line 21 def before(event, &block) add(:before, event, &block) end |
#run_callbacks(event, *args, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rabbitmq_client/lifecycle.rb', line 29 def run_callbacks(event, *args, &block) missing_callback(event) unless @callbacks.key?(event) event_obj = EVENTS[event] event_size = event_obj.size unless event_size == args.size raise ArgumentError, "Callback #{event} expects\ #{event_size} parameter(s): #{event_obj.join(', ')}" end @callbacks[event].execute(*args, &block) end |