Module: Wicked::Controller::Concerns::Steps

Extended by:
ActiveSupport::Concern
Included in:
Wizard
Defined in:
lib/wicked/controller/concerns/steps.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

PROTECTED_STEPS =
[Wicked::FINISH_STEP, Wicked::FIRST_STEP, Wicked::LAST_STEP]

Instance Method Summary collapse

Instance Method Details

#current_step?(step_name) ⇒ Boolean

will return true if step passed in is the currently rendered step

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/wicked/controller/concerns/steps.rb', line 19

def current_step?(step_name)
  return false unless current_and_given_step_exists?(step_name)
  step == step_name
end

#future_step?(step_name) ⇒ Boolean

will return true if the step passed in has not been executed by the wizard

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/wicked/controller/concerns/steps.rb', line 31

def future_step?(step_name)
  return false unless current_and_given_step_exists?(step_name)
  current_step_index < step_index_for(step_name)
end

#jump_to(goto_step) ⇒ Object



6
7
8
# File 'lib/wicked/controller/concerns/steps.rb', line 6

def jump_to(goto_step)
  @skip_to = goto_step
end

#next_step(current_step = nil) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/wicked/controller/concerns/steps.rb', line 86

def next_step(current_step = nil)
  return @next_step if current_step.nil?
  index = steps.index(current_step)
  step  = steps.at(index + 1) if index.present?
  step  ||= Wicked::FINISH_STEP
  step
end

#next_step?(step_name) ⇒ Boolean

will return true if the next step is the step passed in

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/wicked/controller/concerns/steps.rb', line 43

def next_step?(step_name)
  return false unless current_and_given_step_exists?(step_name)
  (current_step_index + 1)  == step_index_for(step_name)
end

#past_step?(step_name) ⇒ Boolean

will return true if the step passed in has already been executed by the wizard

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/wicked/controller/concerns/steps.rb', line 25

def past_step?(step_name)
  return false unless current_and_given_step_exists?(step_name)
  current_step_index > step_index_for(step_name)
end

#previous_step(current_step = nil) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/wicked/controller/concerns/steps.rb', line 77

def previous_step(current_step = nil)
  return @previous_step if current_step.nil?
  index =  steps.index(current_step)
  step  =  steps.at(index - 1) if index.present? && index != 0
  step ||= steps.first
  step
end

#previous_step?(step_name) ⇒ Boolean

will return true if the last step is the step passed in

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/wicked/controller/concerns/steps.rb', line 37

def previous_step?(step_name)
  return false unless current_and_given_step_exists?(step_name)
  (current_step_index - 1)  == step_index_for(step_name)
end

#skip_stepObject



10
11
12
# File 'lib/wicked/controller/concerns/steps.rb', line 10

def skip_step
  @skip_to = @next_step
end

#stepObject



14
15
16
# File 'lib/wicked/controller/concerns/steps.rb', line 14

def step
  @step
end

#stepsObject Also known as: wizard_steps, steps_list



71
72
73
# File 'lib/wicked/controller/concerns/steps.rb', line 71

def steps
  @wizard_steps
end

#steps=(wizard_steps) ⇒ Object



67
68
69
# File 'lib/wicked/controller/concerns/steps.rb', line 67

def steps=(wizard_steps)
  @wizard_steps = wizard_steps
end