Class: WebFlow::ActionStep

Inherits:
FlowStep show all
Defined in:
lib/webflow/action_step.rb

Overview

This class allows the controllers to create action steps. Action steps do nothing but call a method defined in the controller and then route the flow according to it’s events mapping.

Simple usage

action_step :action_name do
  on :success => :another_step
  on :back => :yet_another_step
end

The method identified by :action_name will simply be called and then the flow will be routed to either another_step or yet_another_step steps.

One could also use the action_step instruction to batch define action steps. Simply call the action_step instruction and give it a comma separated list of step names.

action_step :first_step, :second_step do
  (...)
end

Inherited instructions

The ViewStep class inherits all the standard step methods defined in FlowStep class.

Instance Method Summary collapse

Methods inherited from FlowStep

#definition_required?, #handler, #handles?, #has_an_outcome_for?, #method, #on, #outcome, #upon

Constructor Details

#initialize(m_action_name) ⇒ ActionStep

Initializes the instance



58
59
60
61
62
# File 'lib/webflow/action_step.rb', line 58

def initialize( m_action_name )

  @action_name = m_action_name

end

Instance Method Details

#execute(*args) ⇒ Object

This method is required by the WebFlow::Base and will be called once it relays the execution to this step instance

Raises:



67
68
69
70
71
72
73
74
75
76
# File 'lib/webflow/action_step.rb', line 67

def execute(*args)

  # Verify if the controller answers to the @action_name value
  raise WebFlowError, "The action step #{@action_name} is not defined in your controller." unless args[0].respond_to? lookup_method_to_call(@action_name)

  # The controller defines a method with the same name as @action_name.
  # Kewl! A 'someone else problem' !!!
  args[0].send( lookup_method_to_call( @action_name ) )
  
end