Class: Turbine::Pipeline::Journal

Inherits:
Segment
  • Object
show all
Includes:
Trace::Transparent
Defined in:
lib/turbine/pipeline/journal.rb

Overview

Journal segments keep track of all of the values emitted by the source segment so that they can be used later in the pipeline.

Defined Under Namespace

Modules: Read

Instance Attribute Summary collapse

Attributes inherited from Segment

#source

Instance Method Summary collapse

Methods included from Trace::Transparent

#trace

Methods inherited from Segment

#append, #each, #inspect, #trace, #tracing=

Constructor Details

#initialize(name) ⇒ Journal

Public: Creates a new Journal segment.

name - A name which is associated with the values remembered by the

segment. This is required so that the values can be referred to
in later segments.

Returns a Journal instance.



18
19
20
21
22
23
# File 'lib/turbine/pipeline/journal.rb', line 18

def initialize(name)
  super()

  @name = name
  forget!
end

Instance Attribute Details

#nameObject (readonly)

The name used to refer to the segments values later in the pipeline.



9
10
11
# File 'lib/turbine/pipeline/journal.rb', line 9

def name
  @name
end

Instance Method Details

#include?(value) ⇒ Boolean Also known as: member?

Public: Checks if the given value is stored in the Journal. Faster than values.include?.

value - The value to look for.

Returns true or false.

Returns:

  • (Boolean)


67
68
69
70
# File 'lib/turbine/pipeline/journal.rb', line 67

def include?(value)
  @lookup ||= Set.new(values)
  @lookup.include?(value)
end

#nextObject

Public: Run the pipeline once, returning the next value. Forces complete evalulation of the values emitted by the upstream segments.

See Segment#next.

Returns the next value.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/turbine/pipeline/journal.rb', line 39

def next
  values

  if @index >= values.length - 1
    # We test length-1 because the index is always one position *lower*
    # than the actual position at this stage; it is incremented later
    # when calling +input+.
    raise StopIteration
  else
    super
  end
end

#rewindObject

Public: Rewinds the segment so that iteration can happen from the first in put again.

Returns nothing.



56
57
58
59
# File 'lib/turbine/pipeline/journal.rb', line 56

def rewind
  forget!
  super
end

#to_sObject

Public: Describes the segments through which each input will pass.

Return a string.



77
78
79
# File 'lib/turbine/pipeline/journal.rb', line 77

def to_s
  "#{ source_to_s } | as(#{ @name.inspect })"
end

#valuesObject

Public: The values stored by the segment; contains the results of running the upstream segments on all the inputs.

Returns an array.



29
30
31
# File 'lib/turbine/pipeline/journal.rb', line 29

def values
  @values ||= @source.to_a
end