Module: FormJourney::Controller

Extended by:
ActiveSupport::Concern
Defined in:
lib/form_journey/controller.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_step(new_step, before: nil) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/form_journey/controller.rb', line 42

def add_step(new_step, before: nil)
  if before
    index = instance_steps.index(before)
    return nil unless index
    instance_steps.insert(index, new_step)
  else
    instance_steps << new_step
  end
end

#current_stepObject



60
61
62
# File 'lib/form_journey/controller.rb', line 60

def current_step
  steps.include?(params[:action].to_sym) and params[:action].to_sym or steps.first
end

#current_step_numberObject



72
73
74
# File 'lib/form_journey/controller.rb', line 72

def current_step_number
  current_step_index + 1
end

#default_stepObject



26
27
28
# File 'lib/form_journey/controller.rb', line 26

def default_step
  redirect_to steps.any? ? step_path(steps.first) : '/'
end

#instance_stepsObject



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

def instance_steps
  @instance_steps ||= self.class._steps.dup
end

#journey_paramsObject



100
101
102
# File 'lib/form_journey/controller.rb', line 100

def journey_params
  @journey_params ||= FormJourney::Parameters.new(params, journey_session)
end

#next_stepObject



64
65
66
# File 'lib/form_journey/controller.rb', line 64

def next_step
  steps[current_step_index + 1] || steps.last
end

#previous_stepObject



68
69
70
# File 'lib/form_journey/controller.rb', line 68

def previous_step
  steps[current_step_index - 1] || steps.first
end

#remove_step(step_name) ⇒ Object



52
53
54
# File 'lib/form_journey/controller.rb', line 52

def remove_step(step_name)
  instance_steps.delete(step_name)
end

#step_path(step) ⇒ Object



56
57
58
# File 'lib/form_journey/controller.rb', line 56

def step_path(step)
  url_for(controller: params[:controller], action: step)
end

#stepsObject



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

def steps
  instance_steps
end

#total_steps_numberObject



76
77
78
# File 'lib/form_journey/controller.rb', line 76

def total_steps_number
  steps.count
end

#update_steps(*new_steps) ⇒ Object



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

def update_steps(*new_steps)
  @instance_steps = new_steps
end

#when_deleteObject



92
93
94
# File 'lib/form_journey/controller.rb', line 92

def when_delete
  return yield if request.delete?
end

#when_getObject



96
97
98
# File 'lib/form_journey/controller.rb', line 96

def when_get
  return yield if request.get?
end

#when_patchObject



84
85
86
# File 'lib/form_journey/controller.rb', line 84

def when_patch
  return yield if request.patch?
end

#when_postObject



80
81
82
# File 'lib/form_journey/controller.rb', line 80

def when_post
  return yield if request.post?
end

#when_post_or_patchObject



88
89
90
# File 'lib/form_journey/controller.rb', line 88

def when_post_or_patch
  return yield if request.patch? || request.post?
end