Class: Ribbon::EventBus::Subscription

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#instance

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_nameObject (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

#locatorObject (readonly)

Returns the value of attribute locator.



14
15
16
# File 'lib/ribbon/event_bus/subscription.rb', line 14

def locator
  @locator
end

#priorityObject (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