Class: Flor::Journal

Inherits:
Object
  • Object
show all
Defined in:
lib/flor/unit/journal.rb

Overview

As seen in docs/hooks.md

“‘ruby flor.hooker.add(’journal’, Flor::Journal) “‘

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

Instance Method Summary collapse

Constructor Details

#initialize(unit) ⇒ Journal

Returns a new instance of Journal.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/flor/unit/journal.rb', line 23

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'].messages
    end
  end

  @messages = []
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



21
22
23
# File 'lib/flor/unit/journal.rb', line 21

def messages
  @messages
end

Instance Method Details

#notify(executor, message) ⇒ Object

The method used by the hooker to give consumed messages to this journal



51
52
53
54
55
56
57
# File 'lib/flor/unit/journal.rb', line 51

def notify(executor, message)

  @messages << Flor.dup(message)
    # stores a deep clone of each consumed message

  [] # no new messages
end

#optsObject

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.



47
# File 'lib/flor/unit/journal.rb', line 47

def opts; { consumed: true }; end