Class: Chef::ResourceCollection::StepableIterator

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/resource_collection/stepable_iterator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection = []) ⇒ StepableIterator

Returns a new instance of StepableIterator.


29
30
31
32
33
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 29

def initialize(collection = [])
  @position = 0
  @paused = false
  @collection = collection
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection


26
27
28
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 26

def collection
  @collection
end

#positionObject (readonly)

Returns the value of attribute position


27
28
29
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 27

def position
  @position
end

Class Method Details

.for_collection(new_collection) ⇒ Object


22
23
24
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 22

def self.for_collection(new_collection)
  new(new_collection)
end

Instance Method Details

#each(&block) ⇒ Object


39
40
41
42
43
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 39

def each(&block)
  reset_iteration(block)
  @iterator_type = :element
  iterate
end

#each_index(&block) ⇒ Object


45
46
47
48
49
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 45

def each_index(&block)
  reset_iteration(block)
  @iterator_type = :index
  iterate
end

#each_with_index(&block) ⇒ Object


51
52
53
54
55
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 51

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

#pauseObject


61
62
63
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 61

def pause
  @paused = true
end

#paused?Boolean

Returns:

  • (Boolean)

57
58
59
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 57

def paused?
  @paused
end

#resumeObject


65
66
67
68
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 65

def resume
  @paused = false
  iterate
end

#rewindObject


70
71
72
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 70

def rewind
  @position = 0
end

#sizeObject


35
36
37
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 35

def size
  collection.size
end

#skip_back(skips = 1) ⇒ Object


74
75
76
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 74

def skip_back(skips = 1)
  @position -= skips
end

#skip_forward(skips = 1) ⇒ Object


78
79
80
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 78

def skip_forward(skips = 1)
  @position += skips
end

#stepObject


82
83
84
85
86
87
# File 'lib/chef/resource_collection/stepable_iterator.rb', line 82

def step
  return nil if @position == size

  call_iterator_block
  @position += 1
end