Class: Ribbon::EventBus::Subscription
- Inherits:
-
Object
- Object
- Ribbon::EventBus::Subscription
- Includes:
- Mixins::HasConfig, Mixins::HasInstance, Mixins::Serializable
- Defined in:
- lib/ribbon/event_bus/subscription.rb
Constant Summary
Constants included from Mixins::Serializable
Mixins::Serializable::MAGIC, Mixins::Serializable::VERSION
Instance Attribute Summary collapse
-
#event_name ⇒ Object
readonly
Returns the value of attribute event_name.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
Class Method Summary collapse
Instance Method Summary collapse
- #handle(event) ⇒ Object
-
#initialize(event_name, params = {}, &block) ⇒ Subscription
constructor
A new instance of Subscription.
- #to_s ⇒ Object
Methods included from Mixins::Serializable
#_serializable_args, #_serializable_package, #_serialize_arg, included, #serialize
Methods included from Mixins::HasConfig
#_has_config_config, #_has_config_load_config, #config, included
Methods included from Mixins::HasInstance
Constructor Details
#initialize(event_name, params = {}, &block) ⇒ Subscription
Returns a new instance of Subscription.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ribbon/event_bus/subscription.rb', line 17 def initialize(event_name, params={}, &block) @event_name = event_name.to_sym @_block = block _evaluate_params(params) @identifier = _generate_identifier if instance.find_subscription(identifier) raise Errors::DuplicateIdentifierError, "give this subscription a unique name" else instance._register_subscription(self) end end |
Instance Attribute Details
#event_name ⇒ Object (readonly)
Returns the value of attribute event_name.
13 14 15 |
# File 'lib/ribbon/event_bus/subscription.rb', line 13 def event_name @event_name end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
15 16 17 |
# File 'lib/ribbon/event_bus/subscription.rb', line 15 def identifier @identifier end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/ribbon/event_bus/subscription.rb', line 12 def name @name end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
14 15 16 |
# File 'lib/ribbon/event_bus/subscription.rb', line 14 def priority @priority end |
Class Method Details
.load_from_serialized(instance, identifier) ⇒ Object
32 33 34 |
# File 'lib/ribbon/event_bus/subscription.rb', line 32 def self.load_from_serialized(instance, identifier) instance.find_subscription(identifier) end |
Instance Method Details
#handle(event) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/ribbon/event_bus/subscription.rb', line 36 def handle(event) raise Errors::UnexpectedEventError, 'wrong name' unless event.name == event_name raise Errors::UnexpectedEventError, 'wrong instance' unless event.instance == instance plugins.perform(:subscription, self, event) { |subscription, event| @_block.call(event) } end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/ribbon/event_bus/subscription.rb', line 45 def to_s "Subscription(on #{event_name}: #{name || _path})" end |