Module: MultistepForm

Extended by:
ActiveSupport::Inflector
Defined in:
lib/version.rb,
lib/multistep_form.rb

Constant Summary collapse

VERSION =
"0.0.3"
StepsNotDefined =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#current_stepObject



30
31
32
# File 'lib/multistep_form.rb', line 30

def current_step
  @current_step || steps.first
end

#first_step?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/multistep_form.rb', line 12

def first_step?
  current_step == steps.first
end

#force_step(step, as_index = false) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/multistep_form.rb', line 20

def force_step(step, as_index = false)
  if as_index
    @current_step = steps[step]
  else
    @current_step = step
  end
  @current_step ||= steps.first
  session["#{self.class.name.underscore}_current_step"] = @current_step
end

#initialize(*args) ⇒ Object

Raises:



7
8
9
10
# File 'lib/multistep_form.rb', line 7

def initialize(*args)
  raise StepsNotDefined unless defined?(steps)
  super(*args)
end

#last_step?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/multistep_form.rb', line 16

def last_step?
  current_step == steps.last
end

#next_step(&block) ⇒ Object



34
35
36
# File 'lib/multistep_form.rb', line 34

def next_step(&block)
  step(1, &block)
end

#previous_step(&block) ⇒ Object



38
39
40
# File 'lib/multistep_form.rb', line 38

def previous_step(&block)
  step(-1, &block)
end

#step(index, &block) ⇒ Object



42
43
44
45
# File 'lib/multistep_form.rb', line 42

def step(index, &block)
  return if block_given? && block.call == false
  force_step(steps.index(current_step) + index, true)
end