Class: Roast::SystemCogs::Repeat::Input
- Inherits:
-
Cog::Input
- Object
- Cog::Input
- Roast::SystemCogs::Repeat::Input
- Defined in:
- lib/roast/system_cogs/repeat.rb
Overview
Input for the ‘repeat` cog
Provides the initial value to pass to the first iteration. Each subsequent iteration receives the output from the previous iteration as its value.
Instance Attribute Summary collapse
-
#index ⇒ Object
The starting index for the first iteration.
-
#max_iterations ⇒ Object
The maximum number of iterations for which the loop may run.
-
#value ⇒ Object
The initial value to pass to the first iteration.
Instance Method Summary collapse
-
#coerce(input_return_value) ⇒ Object
Coerce the input from the return value of the input block.
-
#initialize ⇒ Input
constructor
Initialize the input with default values.
-
#validate! ⇒ Object
Validate that required input values are present.
Constructor Details
#initialize ⇒ Input
Initialize the input with default values
: () -> void
63 64 65 66 |
# File 'lib/roast/system_cogs/repeat.rb', line 63 def initialize super @index = 0 end |
Instance Attribute Details
#index ⇒ Object
The starting index for the first iteration
Defaults to ‘0`. This affects the index value passed to each iteration.
Integer
51 52 53 |
# File 'lib/roast/system_cogs/repeat.rb', line 51 def index @index end |
#max_iterations ⇒ Object
The maximum number of iterations for which the loop may run
Defaults to ‘nil`, meaning that no maximum iteration limit is applied
: Integer?
58 59 60 |
# File 'lib/roast/system_cogs/repeat.rb', line 58 def max_iterations @max_iterations end |
#value ⇒ Object
The initial value to pass to the first iteration
This value will be passed to the execution scope on the first iteration. Subsequent iterations receive the output from the previous iteration. Required.
: untyped
44 45 46 |
# File 'lib/roast/system_cogs/repeat.rb', line 44 def value @value end |
Instance Method Details
#coerce(input_return_value) ⇒ Object
Coerce the input from the return value of the input block
Sets the value from the input block’s return value if not already set directly.
: (untyped) -> void
81 82 83 84 |
# File 'lib/roast/system_cogs/repeat.rb', line 81 def coerce(input_return_value) super @value = input_return_value unless @value.present? end |
#validate! ⇒ Object
Validate that required input values are present
: () -> void
71 72 73 74 |
# File 'lib/roast/system_cogs/repeat.rb', line 71 def validate! raise Cog::Input::InvalidInputError, "'value' is required" if value.nil? && !coerce_ran? raise Cog::Input::InvalidInputError, "'max_iterations' must be >= 1 if present" if (max_iterations || 1) < 1 end |