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 collapse
- PRIORITY_SYMBOL_TO_INTEGER_MAP =
{ highest: 1, high: 3, medium: 5, low: 7, lowest: 10 }.freeze
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.
-
#locator ⇒ Object
readonly
Returns the value of attribute locator.
-
#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.
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.
24 25 26 27 28 29 30 31 32 |
# File 'lib/ribbon/event_bus/subscription.rb', line 24 def initialize(event_name, params={}, &block) @event_name = event_name.to_sym @_block = block _evaluate_params(params) _generate_locator instance._register_subscription(self) end |
Instance Attribute Details
#event_name ⇒ Object (readonly)
Returns the value of attribute event_name.
12 13 14 |
# File 'lib/ribbon/event_bus/subscription.rb', line 12 def event_name @event_name end |
#locator ⇒ Object (readonly)
Returns the value of attribute locator.
14 15 16 |
# File 'lib/ribbon/event_bus/subscription.rb', line 14 def locator @locator end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
13 14 15 |
# File 'lib/ribbon/event_bus/subscription.rb', line 13 def priority @priority end |
Class Method Details
.load_from_serialized(instance, locator) ⇒ Object
34 35 36 |
# File 'lib/ribbon/event_bus/subscription.rb', line 34 def self.load_from_serialized(instance, locator) instance.find_subscription(locator) end |
Instance Method Details
#handle(event) ⇒ Object
38 39 40 41 42 |
# File 'lib/ribbon/event_bus/subscription.rb', line 38 def handle(event) raise Errors::UnexpectedEventError, 'wrong name' unless event.name == event_name raise Errors::UnexpectedEventError, 'wrong instance' unless event.instance == instance @_block.call(event) end |