Class: Observatory::Event
- Inherits:
-
Hash
- Object
- Hash
- Observatory::Event
- Defined in:
- lib/observatory/event.rb
Overview
An event is essentially a Hash with some extra properties, so you can use all the regular Hash and Enumerable methods to your liking.
An Event is a value object that the observable passes along to the observers. It gives observers easy access to the original observable and any additional values it may have wanted to pass along (the parameters).
The event object is also returned back to the observable that originally issued it, so it also works as a value object to pass information from the observers to the observable. The event knows whether it has been acted upon, and it can remember a return value that the observable may want to use (and other observers may want to act upon).
The event works just like a regular Ruby Hash, so you can access any parameters just like you would with a hash.
Instance Attribute Summary collapse
-
#observable ⇒ Object
readonly
The original observable object that issued the event.
-
#return_value ⇒ Object
The return value for the observable, that observers may modify.
-
#signal ⇒ String
readonly
The name of the signal that the observable triggered.
Instance Method Summary collapse
-
#initialize(observable, signal, parameters = {}) ⇒ Event
constructor
Create a new event instance with the given observable and signal.
-
#process! ⇒ Boolean
Mark this event as processed, so the observable knows an observer was active when using Dispatcher#notify_until.
-
#processed? ⇒ Boolean
See if this event has been processed by an observer.
Constructor Details
#initialize(observable, signal, parameters = {}) ⇒ Event
Create a new event instance with the given observable and signal. Any parameters are stored, which you can later access like a hash.
44 45 46 47 48 49 |
# File 'lib/observatory/event.rb', line 44 def initialize(observable, signal, parameters = {}) @observable, @signal = observable, signal.to_s merge! parameters @processed = false super() end |
Instance Attribute Details
#observable ⇒ Object (readonly)
The original observable object that issued the event.
26 27 28 |
# File 'lib/observatory/event.rb', line 26 def observable @observable end |
#return_value ⇒ Object
The return value for the observable, that observers may modify.
35 36 37 |
# File 'lib/observatory/event.rb', line 35 def return_value @return_value end |
#signal ⇒ String (readonly)
The name of the signal that the observable triggered. Namespaced with periods.
31 32 33 |
# File 'lib/observatory/event.rb', line 31 def signal @signal end |
Instance Method Details
#process! ⇒ Boolean
Mark this event as processed, so the observable knows an observer was active when using Dispatcher#notify_until.
66 67 68 |
# File 'lib/observatory/event.rb', line 66 def process! @processed = true end |
#processed? ⇒ Boolean
See if this event has been processed by an observer. Useful when using Dispatcher#notify_until to see if there was any observer that actually did something.
57 58 59 |
# File 'lib/observatory/event.rb', line 57 def processed? @processed end |