Class: Chef::ResourceCollection::StepableIterator
- Inherits:
-
Object
- Object
- Chef::ResourceCollection::StepableIterator
- Defined in:
- lib/chef/resource_collection/stepable_iterator.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Class Method Summary collapse
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #each_index(&block) ⇒ Object
- #each_with_index(&block) ⇒ Object
-
#initialize(collection = []) ⇒ StepableIterator
constructor
A new instance of StepableIterator.
- #iterate_on(iteration_type, &block) ⇒ Object
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #resume ⇒ Object
- #rewind ⇒ Object
- #size ⇒ Object
- #skip_back(skips = 1) ⇒ Object
- #skip_forward(skips = 1) ⇒ Object
- #step ⇒ Object
Constructor Details
#initialize(collection = []) ⇒ StepableIterator
Returns a new instance of StepableIterator.
30 31 32 33 34 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 30 def initialize(collection=[]) @position = 0 @paused = false @collection = collection end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
27 28 29 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 27 def collection @collection end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
28 29 30 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 28 def position @position end |
Class Method Details
.for_collection(new_collection) ⇒ Object
22 23 24 25 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 22 def self.for_collection(new_collection) instance = new(new_collection) instance end |
Instance Method Details
#each(&block) ⇒ Object
40 41 42 43 44 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 40 def each(&block) reset_iteration(block) @iterator_type = :element iterate end |
#each_index(&block) ⇒ Object
46 47 48 49 50 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 46 def each_index(&block) reset_iteration(block) @iterator_type = :index iterate end |
#each_with_index(&block) ⇒ Object
52 53 54 55 56 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 52 def each_with_index(&block) reset_iteration(block) @iterator_type = :element_with_index iterate end |
#iterate_on(iteration_type, &block) ⇒ Object
89 90 91 92 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 89 def iterate_on(iteration_type, &block) @iterator_type = iteration_type @iterator_block = block end |
#pause ⇒ Object
62 63 64 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 62 def pause @paused = true end |
#paused? ⇒ Boolean
58 59 60 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 58 def paused? @paused end |
#resume ⇒ Object
66 67 68 69 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 66 def resume @paused = false iterate end |
#rewind ⇒ Object
71 72 73 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 71 def rewind @position = 0 end |
#size ⇒ Object
36 37 38 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 36 def size collection.size end |
#skip_back(skips = 1) ⇒ Object
75 76 77 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 75 def skip_back(skips=1) @position -= skips end |
#skip_forward(skips = 1) ⇒ Object
79 80 81 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 79 def skip_forward(skips=1) @position += skips end |
#step ⇒ Object
83 84 85 86 87 |
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 83 def step return nil if @position == size call_iterator_block @position += 1 end |