Class: Dao::Gateway::Iterator
- Inherits:
-
Object
- Object
- Dao::Gateway::Iterator
- Includes:
- Enumerable
- Defined in:
- lib/dao/gateway/iterator.rb
Instance Attribute Summary collapse
-
#pipe ⇒ Object
readonly
Returns the value of attribute pipe.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #fork ⇒ Object
- #fork! ⇒ Object
-
#initialize(data, pipe, associations) ⇒ Iterator
constructor
A new instance of Iterator.
- #length ⇒ Object (also: #size)
- #processed? ⇒ Boolean
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
#pipe ⇒ Object (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 |
#fork ⇒ Object
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 |
#length ⇒ Object Also known as: size
19 20 21 |
# File 'lib/dao/gateway/iterator.rb', line 19 def length @data.length end |
#processed? ⇒ Boolean
15 16 17 |
# File 'lib/dao/gateway/iterator.rb', line 15 def processed? @data_processed end |