Class: Dao::Gateway::Iterator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/dao/gateway/iterator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, pipe, associations) ⇒ Iterator

Returns a new instance of Iterator.



8
9
10
11
12
13
# File 'lib/dao/gateway/iterator.rb', line 8

def initialize(data, pipe, associations)
  @data = data
  @pipe = pipe
  @associations = associations
  @data_processed = false
end

Instance Attribute Details

#pipeObject (readonly)

Returns the value of attribute pipe.



6
7
8
# File 'lib/dao/gateway/iterator.rb', line 6

def pipe
  @pipe
end

Instance Method Details

#each(&block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/dao/gateway/iterator.rb', line 25

def each(&block)
  if processed?
    @data.each(&block)
  else
    process_data(&block)
  end
end

#forkObject



33
34
35
36
# File 'lib/dao/gateway/iterator.rb', line 33

def fork
  raise 'Data was already processed' if processed?
  fork!
end

#fork!Object



38
39
40
# File 'lib/dao/gateway/iterator.rb', line 38

def fork!
  self.class.new(@data.dup, pipe.dup, @associations)
end

#lengthObject Also known as: size



19
20
21
# File 'lib/dao/gateway/iterator.rb', line 19

def length
  @data.length
end

#processed?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/dao/gateway/iterator.rb', line 15

def processed?
  @data_processed
end