Module: FormJourney::Controller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/form_journey/controller.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #add_step(new_step, before: nil) ⇒ Object
- #current_step ⇒ Object
- #current_step_number ⇒ Object
- #default_step ⇒ Object
- #instance_steps ⇒ Object
- #journey_params ⇒ Object
- #next_step ⇒ Object
- #previous_step ⇒ Object
- #remove_step(step_name) ⇒ Object
- #step_path(step, query_params = {}) ⇒ Object
- #steps ⇒ Object
- #total_steps_number ⇒ Object
- #update_steps(*new_steps) ⇒ Object
- #when_delete ⇒ Object
- #when_get ⇒ Object
- #when_patch ⇒ Object
- #when_post ⇒ Object
- #when_post_or_patch ⇒ Object
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_step ⇒ Object
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_number ⇒ Object
77 78 79 |
# File 'lib/form_journey/controller.rb', line 77 def current_step_number current_step_index + 1 end |
#default_step ⇒ Object
27 28 29 |
# File 'lib/form_journey/controller.rb', line 27 def default_step redirect_to steps.any? ? step_path(steps.first) : '/' end |
#instance_steps ⇒ Object
35 36 37 |
# File 'lib/form_journey/controller.rb', line 35 def instance_steps @instance_steps ||= self.class._steps.dup end |
#journey_params ⇒ Object
105 106 107 |
# File 'lib/form_journey/controller.rb', line 105 def journey_params @journey_params ||= FormJourney::Parameters.new(params, journey_session) end |
#next_step ⇒ Object
69 70 71 |
# File 'lib/form_journey/controller.rb', line 69 def next_step steps[current_step_index + 1] || steps.last end |
#previous_step ⇒ Object
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 |
#steps ⇒ Object
31 32 33 |
# File 'lib/form_journey/controller.rb', line 31 def steps instance_steps end |
#total_steps_number ⇒ Object
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_delete ⇒ Object
97 98 99 |
# File 'lib/form_journey/controller.rb', line 97 def when_delete return yield if request.delete? end |
#when_get ⇒ Object
101 102 103 |
# File 'lib/form_journey/controller.rb', line 101 def when_get return yield if request.get? end |
#when_patch ⇒ Object
89 90 91 |
# File 'lib/form_journey/controller.rb', line 89 def when_patch return yield if request.patch? end |
#when_post ⇒ Object
85 86 87 |
# File 'lib/form_journey/controller.rb', line 85 def when_post return yield if request.post? end |
#when_post_or_patch ⇒ Object
93 94 95 |
# File 'lib/form_journey/controller.rb', line 93 def when_post_or_patch return yield if request.patch? || request.post? end |