Class: Pug::Action::Controller
- Inherits:
-
Object
- Object
- Pug::Action::Controller
- Defined in:
- lib/pug/action/controller.rb
Overview
Controls the execution of an Action serially
Instance Method Summary collapse
-
#action_input ⇒ Input
Provides information about the Action’s input requirements.
-
#actions? ⇒ Boolean
Indicates if there are any actions to manage.
-
#can_start_action?(index) ⇒ Boolean
Determines if an Action can start for a given index.
-
#initialize(actions) ⇒ Controller
constructor
A new instance of Controller.
-
#run_action(input) ⇒ Pug::Types::Result
Runs the Action prepared by #start_action with provided input.
-
#running_action? ⇒ Boolean
Indicates if there is a currently running Action.
-
#start_action(index) ⇒ Object
Starts up the Action at the given index if possible.
Constructor Details
#initialize(actions) ⇒ Controller
Returns a new instance of Controller.
8 9 10 11 |
# File 'lib/pug/action/controller.rb', line 8 def initialize(actions) @current_action = nil @actions = actions || [] end |
Instance Method Details
#action_input ⇒ Input
Provides information about the Action’s input requirements
27 28 29 30 31 |
# File 'lib/pug/action/controller.rb', line 27 def action_input raise Strings.no_action_running unless running_action? input_required = @current_action.requires_input? Input.new(@current_action.name, input_required) end |
#actions? ⇒ Boolean
Indicates if there are any actions to manage
15 16 17 |
# File 'lib/pug/action/controller.rb', line 15 def actions? !@actions.empty? end |
#can_start_action?(index) ⇒ Boolean
This will return false if there is a currently running action
Determines if an Action can start for a given index
37 38 39 40 |
# File 'lib/pug/action/controller.rb', line 37 def can_start_action?(index) return false if index.negative? || index >= @actions.length !running_action? end |
#run_action(input) ⇒ Pug::Types::Result
Runs the Action prepared by #start_action with provided input
54 55 56 57 58 59 60 61 62 |
# File 'lib/pug/action/controller.rb', line 54 def run_action(input) return Results.no_action_running unless running_action? requires_input = @current_action.requires_input? result = @current_action.execute(requires_input ? input : nil) output = Output.new(@current_action.name, result || '') @current_action = nil Types::Result.success(output) end |
#running_action? ⇒ Boolean
Indicates if there is a currently running Action
21 22 23 |
# File 'lib/pug/action/controller.rb', line 21 def running_action? !@current_action.nil? end |
#start_action(index) ⇒ Object
Starts up the Action at the given index if possible
44 45 46 47 48 49 |
# File 'lib/pug/action/controller.rb', line 44 def start_action(index) return unless can_start_action?(index) action = @actions[index] @current_action = action end |