Class: Roast::Cog::Input
- Inherits:
-
Object
- Object
- Roast::Cog::Input
- Defined in:
- lib/roast/cog/input.rb
Overview
Abstract parent class for inputs provided to a cog when it runs
Cogs extend this class to define their own input types that specify what data the cog needs to execute. Input classes must be instantiatable with a no-argument constructor and expose methods to incrementally set their values.
The input lifecycle:
- An input instance is created when the cog is invoked
- The
validate!method is called to see if all required parameters are set correctly (errors are swallowed) - If validation fails, the
coercemethod is called with the return value from the input block (if provided) - The
validate!method is called again to ensure all required parameters are set correctly (errors are raised) - The validated input is passed to the cog's
executemethod
Direct Known Subclasses
Roast::Cogs::Agent::Input, Roast::Cogs::Chat::Input, Roast::Cogs::Cmd::Input, Roast::Cogs::Ruby::Input, SystemCogs::Call::Input, SystemCogs::Map::Input, SystemCogs::Repeat::Input
Defined Under Namespace
Classes: InputError, InvalidInputError
Instance Method Summary collapse
-
#coerce(input_return_value) ⇒ Object
Use the value returned from the cog's input block to coerce the input to a valid state.
-
#validate! ⇒ Object
Validate that the input instance has all required parameters set in an acceptable manner.
Instance Method Details
#coerce(input_return_value) ⇒ Object
Use the value returned from the cog's input block to coerce the input to a valid state
Subclasses may implement this method to automatically configure the input based on the return value from the input block. This is optional; if not implemented, the default behavior is to do nothing.
See Also
validate!
: (untyped) -> void
48 49 50 |
# File 'lib/roast/cog/input.rb', line 48 def coerce(input_return_value) @coerce_ran = true end |
#validate! ⇒ Object
Validate that the input instance has all required parameters set in an acceptable manner
Subclasses must implement this method to verify that the input is in a valid state before
the cog executes. This method should raise an InvalidInputError if the input is not valid.
See Also
coerce
: () -> void
34 35 36 |
# File 'lib/roast/cog/input.rb', line 34 def validate! raise NotImplementedError end |