Class: Roast::Cog::Input

Inherits:
Object
  • Object
show all
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:

  1. An input instance is created when the cog is invoked
  2. The validate! method is called to see if all required parameters are set correctly (errors are swallowed)
  3. If validation fails, the coerce method is called with the return value from the input block (if provided)
  4. The validate! method is called again to ensure all required parameters are set correctly (errors are raised)
  5. The validated input is passed to the cog's execute method

Defined Under Namespace

Classes: InputError, InvalidInputError

Instance Method Summary collapse

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

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/roast/cog/input.rb', line 34

def validate!
  raise NotImplementedError
end