Class: Solid::Result::EventLogs::Listeners::Chain
- Inherits:
-
Object
- Object
- Solid::Result::EventLogs::Listeners::Chain
- Includes:
- Solid::Result::EventLogs::Listener
- Defined in:
- lib/solid/result/event_logs/listeners.rb
Instance Attribute Summary collapse
-
#listeners ⇒ Object
readonly
Returns the value of attribute listeners.
Instance Method Summary collapse
-
#initialize(list) ⇒ Chain
constructor
A new instance of Chain.
- #new ⇒ Object
Methods included from Solid::Result::EventLogs::Listener
#around_and_then, #around_event_logs, #before_interruption, extended, included, kind?, #on_finish, #on_record, #on_start
Constructor Details
#initialize(list) ⇒ Chain
Returns a new instance of Chain.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/solid/result/event_logs/listeners.rb', line 10 def initialize(list) if list.empty? || list.any? { !Listener.kind?(_1) } raise ArgumentError, "listeners must be a list of #{Listener}" end around_and_then = list.select(&:around_and_then?) around_event_logs = list.select(&:around_event_logs?) raise ArgumentError, 'only one listener can have around_and_then? == true' if around_and_then.size > 1 raise ArgumentError, 'only one listener can have around_event_logs? == true' if around_event_logs.size > 1 @listeners = { list: list, around_and_then: around_and_then[0], around_event_logs: around_event_logs[0] } end |
Instance Attribute Details
#listeners ⇒ Object (readonly)
Returns the value of attribute listeners.
8 9 10 |
# File 'lib/solid/result/event_logs/listeners.rb', line 8 def listeners @listeners end |
Instance Method Details
#new ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/solid/result/event_logs/listeners.rb', line 24 def new list, around_and_then, around_event_logs = listeners[:list], nil, nil instances = list.map do |item| instance = item.new around_and_then = instance if listener?(:around_and_then, instance) around_event_logs = instance if listener?(:around_event_logs, instance) instance end list.one? ? list[0].new : Listeners.send(:new, instances, around_and_then, around_event_logs) end |