Class: Kernai::Recorder::Sink::CompositeSink

Inherits:
Base
  • Object
show all
Defined in:
lib/kernai/recorder.rb

Overview

Fan-out sink: forwards every entry to each child in declaration order. Entry queries are delegated to the first child, which is why MemorySink should usually be declared first when mixing it with non-queryable persistence sinks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*sinks) ⇒ CompositeSink

Returns a new instance of CompositeSink.

Raises:

  • (ArgumentError)


66
67
68
69
70
71
# File 'lib/kernai/recorder.rb', line 66

def initialize(*sinks)
  super()
  raise ArgumentError, 'CompositeSink needs at least one child sink' if sinks.empty?

  @sinks = sinks
end

Instance Attribute Details

#sinksObject (readonly)

Returns the value of attribute sinks.



64
65
66
# File 'lib/kernai/recorder.rb', line 64

def sinks
  @sinks
end

Instance Method Details

#clear!Object



81
82
83
# File 'lib/kernai/recorder.rb', line 81

def clear!
  @sinks.each(&:clear!)
end

#entriesObject



77
78
79
# File 'lib/kernai/recorder.rb', line 77

def entries
  @sinks.first.entries
end

#record(entry) ⇒ Object



73
74
75
# File 'lib/kernai/recorder.rb', line 73

def record(entry)
  @sinks.each { |sink| sink.record(entry) }
end