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



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

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



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

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

#current_step_numberObject



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

def current_step_number
  current_step_index + 1
end

#default_stepObject



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

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

#instance_stepsObject



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

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

#journey_paramsObject



105
106
107
# File 'lib/form_journey/controller.rb', line 105

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

#next_stepObject



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

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

#previous_stepObject



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

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

#remove_step(step_name) ⇒ Object



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

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

#step_path(step, query_params = {}) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/form_journey/controller.rb', line 57

def step_path(step, query_params = {})
  url_opts = query_params.merge(
    controller: params[:controller],
    action: step,
    journey_session_key: journey_session_key)
  url_for(url_opts)
end

#stepsObject



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

def steps
  instance_steps
end

#total_steps_numberObject



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

def total_steps_number
  steps.count
end

#update_steps(*new_steps) ⇒ Object



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

def update_steps(*new_steps)
  @instance_steps = new_steps
end

#when_deleteObject



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

def when_delete
  return yield if request.delete?
end

#when_getObject



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

def when_get
  return yield if request.get?
end

#when_patchObject



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

def when_patch
  return yield if request.patch?
end

#when_postObject



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

def when_post
  return yield if request.post?
end

#when_post_or_patchObject



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

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