Class: AwsCftTools::TemplateSet::EachSliceState
- Inherits:
-
Object
- Object
- AwsCftTools::TemplateSet::EachSliceState
- Defined in:
- lib/aws_cft_tools/template_set/each_slice_state.rb
Overview
Keeps track of state for the .each_slice(n) method.
Instance Method Summary collapse
-
#add_template(template, dependencies = []) ⇒ Object
Add the template to the current slice and process the slice if it reaches the maximum slice size.
-
#fulfilled?(deps) ⇒ Boolean
Have all of the listed dependencies been seen in prior yields?.
-
#initialize(slice_size) {|Array<AwsCftTools::Template>| ... } ⇒ EachSliceState
constructor
A new instance of EachSliceState.
-
#process_slice ⇒ Integer
Pass the current slice through the block and reset for the next slice.
Constructor Details
#initialize(slice_size) {|Array<AwsCftTools::Template>| ... } ⇒ EachSliceState
Returns a new instance of EachSliceState.
13 14 15 16 17 18 |
# File 'lib/aws_cft_tools/template_set/each_slice_state.rb', line 13 def initialize(slice_size, &block) @seen = [] @size = slice_size @slice = [] @block = block end |
Instance Method Details
#add_template(template, dependencies = []) ⇒ Object
Add the template to the current slice and process the slice if it reaches the maximum slice size.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aws_cft_tools/template_set/each_slice_state.rb', line 35 def add_template(template, dependencies = []) process_slice unless fulfilled?(dependencies) unless fulfilled?(dependencies) raise AwsCftTools::UnsatisfiedDependencyError, "Unable to process #{template.filename}" end @slice << template process_slice if @slice.count == @size end |
#fulfilled?(deps) ⇒ Boolean
Have all of the listed dependencies been seen in prior yields?
26 27 28 |
# File 'lib/aws_cft_tools/template_set/each_slice_state.rb', line 26 def fulfilled?(deps) (deps - @seen).empty? end |
#process_slice ⇒ Integer
Pass the current slice through the block and reset for the next slice.
51 52 53 54 55 |
# File 'lib/aws_cft_tools/template_set/each_slice_state.rb', line 51 def process_slice @block.call(@slice) if @slice.any? @seen |= @slice.map(&:filename).map(&:to_s) @slice = [] end |