class Dao::Gateway::Iterator
Attributes
pipe[R]
Public Class Methods
new(data, pipe, associations)
click to toggle source
# File lib/dao/gateway/iterator.rb, line 8 def initialize(data, pipe, associations) @data = data @pipe = pipe @associations = associations @data_processed = false end
Public Instance Methods
each(&block)
click to toggle source
# File lib/dao/gateway/iterator.rb, line 25 def each(&block) if processed? @data.each(&block) else process_data(&block) end end
fork()
click to toggle source
# File lib/dao/gateway/iterator.rb, line 33 def fork raise 'Data was already processed' if processed? fork! end
fork!()
click to toggle source
# File lib/dao/gateway/iterator.rb, line 38 def fork! self.class.new(@data.dup, pipe.dup, @associations) end
length()
click to toggle source
# File lib/dao/gateway/iterator.rb, line 19 def length @data.length end
Also aliased as: size
processed?()
click to toggle source
# File lib/dao/gateway/iterator.rb, line 15 def processed? @data_processed end
Private Instance Methods
process_data(&block)
click to toggle source
# File lib/dao/gateway/iterator.rb, line 44 def process_data(&block) @data_processed = true result = [] @data.each_with_index do |raw_element, index| entity = pipe.process(raw_element, @associations) result[index] = entity block.call(entity) end @data = result end