module FormJourney::Controller
Public Instance Methods
add_step(new_step, before: nil)
click to toggle source
# 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_step()
click to toggle source
# 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_number()
click to toggle source
# File lib/form_journey/controller.rb, line 77 def current_step_number current_step_index + 1 end
default_step()
click to toggle source
# File lib/form_journey/controller.rb, line 27 def default_step redirect_to steps.any? ? step_path(steps.first) : '/' end
instance_steps()
click to toggle source
# File lib/form_journey/controller.rb, line 35 def instance_steps @instance_steps ||= self.class._steps.dup end
journey_params()
click to toggle source
# File lib/form_journey/controller.rb, line 105 def journey_params @journey_params ||= FormJourney::Parameters.new(params, journey_session) end
next_step()
click to toggle source
# File lib/form_journey/controller.rb, line 69 def next_step steps[current_step_index + 1] || steps.last end
previous_step()
click to toggle source
# File lib/form_journey/controller.rb, line 73 def previous_step steps[current_step_index - 1] || steps.first end
remove_step(step_name)
click to toggle source
# File lib/form_journey/controller.rb, line 53 def remove_step(step_name) instance_steps.delete(step_name) end
step_path(step, query_params = {})
click to toggle source
# 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
steps()
click to toggle source
# File lib/form_journey/controller.rb, line 31 def steps instance_steps end
total_steps_number()
click to toggle source
# File lib/form_journey/controller.rb, line 81 def total_steps_number steps.count end
update_steps(*new_steps)
click to toggle source
# File lib/form_journey/controller.rb, line 39 def update_steps(*new_steps) @instance_steps = new_steps end
when_delete() { || ... }
click to toggle source
# File lib/form_journey/controller.rb, line 97 def when_delete return yield if request.delete? end
when_get() { || ... }
click to toggle source
# File lib/form_journey/controller.rb, line 101 def when_get return yield if request.get? end
when_patch() { || ... }
click to toggle source
# File lib/form_journey/controller.rb, line 89 def when_patch return yield if request.patch? end
when_post() { || ... }
click to toggle source
# File lib/form_journey/controller.rb, line 85 def when_post return yield if request.post? end
when_post_or_patch() { || ... }
click to toggle source
# File lib/form_journey/controller.rb, line 93 def when_post_or_patch return yield if request.patch? || request.post? end
Private Instance Methods
before_step_action()
click to toggle source
# File lib/form_journey/controller.rb, line 121 def before_step_action method = "before_#{current_step}" return self.send(method) if self.respond_to?(method, true) end
current_step_index()
click to toggle source
# File lib/form_journey/controller.rb, line 117 def current_step_index steps.index(current_step) end
fetch_journey_session_key()
click to toggle source
# File lib/form_journey/controller.rb, line 126 def fetch_journey_session_key param_key = params[:journey_session_key] return param_key if param_key SecureRandom.hex end
journey_session()
click to toggle source
# File lib/form_journey/controller.rb, line 140 def journey_session (session[journey_session_name] ||= {}) end
journey_session_key()
click to toggle source
# File lib/form_journey/controller.rb, line 132 def journey_session_key @journey_session_key ||= fetch_journey_session_key end
journey_session_name()
click to toggle source
# File lib/form_journey/controller.rb, line 136 def journey_session_name [controller_name, 'journey_session', journey_session_key].join('_').to_sym end
previous_steps()
click to toggle source
# File lib/form_journey/controller.rb, line 111 def previous_steps Array(steps.clone).tap do |steps| steps.slice!(current_step_index + 1, steps.length) end end