Module: Informator
- Defined in:
- lib/informator.rb,
lib/informator/event.rb,
lib/informator/reporter.rb,
lib/informator/subscriber.rb
Overview
The module provides subscribe/publish/report features
Defined Under Namespace
Classes: Event, Reporter, Subscriber
Instance Method Summary collapse
-
#publish(*args) ⇒ Array<Informator::Event>
List of events having been published.
-
#publish!(*args) ⇒ Object
The same as ‘publish` except for it throws `:published` afterwards.
-
#remember(type, messages, attributes) ⇒ self
Builds and stores the event waiting for being published.
-
#subscribe(listener, callback = :receive) ⇒ self
Subscribes the listener for receiving events notifications via callback.
Instance Method Details
#publish(type, messages, attributes) ⇒ Array<Informator::Event> #publish ⇒ Array<Informator::Event>
Returns list of events having been published.
53 54 55 56 |
# File 'lib/informator.rb', line 53 def publish(*args) remember(*args) if args.any? __reporter__.notify __subscribers__ end |
#publish(type, messages, attributes) ⇒ Object #publish ⇒ Object
The same as ‘publish` except for it throws `:published` afterwards
71 72 73 |
# File 'lib/informator.rb', line 71 def publish!(*args) throw :published, publish(*args) end |
#remember(type, messages, attributes) ⇒ self
Builds and stores the event waiting for being published
37 38 39 40 41 |
# File 'lib/informator.rb', line 37 def remember(*args) __reporter__.remember(*args) self end |
#subscribe(listener, callback = :receive) ⇒ self
Subscribes the listener for receiving events notifications via callback
23 24 25 26 27 28 |
# File 'lib/informator.rb', line 23 def subscribe(listener, callback = :receive) sub = Subscriber.new(listener, callback) __subscribers__ << sub unless __subscribers__.include? sub self end |