Class: Announcer::Event
- Inherits:
-
Object
- Object
- Announcer::Event
- Includes:
- Mixins::HasConfig, Mixins::HasInstance, Mixins::Serializable
- Defined in:
- lib/announcer/event.rb
Constant Summary
Constants included from Mixins::Serializable
Mixins::Serializable::MAGIC, Mixins::Serializable::VERSION
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(name, params = {}) ⇒ Event
constructor
A new instance of Event.
- #publish ⇒ Object
- #subscriptions ⇒ Object
- #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(name, params = {}) ⇒ Event
Returns a new instance of Event.
13 14 15 16 17 |
# File 'lib/announcer/event.rb', line 13 def initialize(name, params={}) raise ArgumentError, 'missing event name' unless name.respond_to?(:to_sym) @name = name.to_sym _evaluate_params(params) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/announcer/event.rb', line 10 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
11 12 13 |
# File 'lib/announcer/event.rb', line 11 def params @params end |
Class Method Details
.load_from_serialized(name, instance, params) ⇒ Object
19 20 21 |
# File 'lib/announcer/event.rb', line 19 def self.load_from_serialized(name, instance, params) new(name, params.merge(instance: instance)) end |
Instance Method Details
#[](key) ⇒ Object
23 24 25 |
# File 'lib/announcer/event.rb', line 23 def [](key) params[key] end |
#publish ⇒ Object
27 28 29 30 31 |
# File 'lib/announcer/event.rb', line 27 def publish plugins.perform(:publish, self) { |event| instance.publishers.each { |p| p.publish(event) } } end |
#subscriptions ⇒ Object
33 34 35 |
# File 'lib/announcer/event.rb', line 33 def subscriptions instance.subscriptions_to(self) end |
#to_s ⇒ Object
37 38 39 40 41 |
# File 'lib/announcer/event.rb', line 37 def to_s "Event(#{name}" << (params && !params.empty? && ", #{params.inspect}" or '') << ")" end |