Class: Flor::Journal
- Inherits:
-
Object
- Object
- Flor::Journal
- Defined in:
- lib/flor/unit/journal.rb
Overview
A Journal hook, receives only “consumed” messages and keeps a copy of all of them.
Used in specs, do not uses as-is in production, since it simply grows in memory…
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
-
#initialize(unit) ⇒ Journal
constructor
A new instance of Journal.
-
#notify(executor, message) ⇒ Object
The method used by the hooker to give consumed messages to this journal.
-
#opts ⇒ Object
Tells the hooker that this hook is only interested in message that have been “consumed”, remember, the hooker passes messages to hooks before consumption and after consumption.
Constructor Details
#initialize(unit) ⇒ Journal
Returns a new instance of Journal.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/flor/unit/journal.rb', line 15 def initialize(unit) # Add a #journal method to the flor unit so that # `unit.journal` yields the message list. # unit.singleton_class.instance_eval do define_method(:journal) do @hooker['journal']. end end @messages = [] end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
13 14 15 |
# File 'lib/flor/unit/journal.rb', line 13 def @messages end |
Instance Method Details
#notify(executor, message) ⇒ Object
The method used by the hooker to give consumed messages to this journal
43 44 45 46 47 48 49 |
# File 'lib/flor/unit/journal.rb', line 43 def notify(executor, ) @messages << Flor.dup() # stores a deep clone of each consumed message [] # no new messages end |
#opts ⇒ Object
Tells the hooker that this hook is only interested in message that have been “consumed”, remember, the hooker passes messages to hooks before consumption and after consumption. In this case only consumed messages are passed.
Other hooks may declare they are only interested in messages belonging to a certain domain or having a certain tag. See spec/unit/unit_hooks_spec.rb for more filtering examples.
39 |
# File 'lib/flor/unit/journal.rb', line 39 def opts; { consumed: true }; end |