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)


21
22
23
24
# File 'lib/wicked/controller/concerns/steps.rb', line 21

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)


33
34
35
36
# File 'lib/wicked/controller/concerns/steps.rb', line 33

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, options = {}) ⇒ Object



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

def jump_to(goto_step, options = {})
  @skip_to                = goto_step
  @wicked_redirect_params = options
end

#next_step(current_step = nil) ⇒ Object



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

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
end

#next_step?(step_name) ⇒ Boolean

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

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/wicked/controller/concerns/steps.rb', line 45

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)


27
28
29
30
# File 'lib/wicked/controller/concerns/steps.rb', line 27

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



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

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
end

#previous_step?(step_name) ⇒ Boolean

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

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/wicked/controller/concerns/steps.rb', line 39

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_step(options = {}) ⇒ Object



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

def skip_step(options = {})
  @skip_to                = @next_step
  @wicked_redirect_params = options
end

#stepObject



16
17
18
# File 'lib/wicked/controller/concerns/steps.rb', line 16

def step
  @step
end

#stepsObject Also known as: wizard_steps, steps_list



73
74
75
# File 'lib/wicked/controller/concerns/steps.rb', line 73

def steps
  @wizard_steps
end

#steps=(wizard_steps) ⇒ Object



69
70
71
# File 'lib/wicked/controller/concerns/steps.rb', line 69

def steps=(wizard_steps)
  @wizard_steps = wizard_steps
end