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) ⇒ 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
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_step ⇒ Object
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_number ⇒ Object
72 73 74 |
# File 'lib/form_journey/controller.rb', line 72 def current_step_number current_step_index + 1 end |
#default_step ⇒ Object
26 27 28 |
# File 'lib/form_journey/controller.rb', line 26 def default_step redirect_to steps.any? ? step_path(steps.first) : '/' end |
#instance_steps ⇒ Object
34 35 36 |
# File 'lib/form_journey/controller.rb', line 34 def instance_steps @instance_steps ||= self.class._steps.dup end |
#journey_params ⇒ Object
100 101 102 |
# File 'lib/form_journey/controller.rb', line 100 def journey_params @journey_params ||= FormJourney::Parameters.new(params, journey_session) end |
#next_step ⇒ Object
64 65 66 |
# File 'lib/form_journey/controller.rb', line 64 def next_step steps[current_step_index + 1] || steps.last end |
#previous_step ⇒ Object
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 |
#steps ⇒ Object
30 31 32 |
# File 'lib/form_journey/controller.rb', line 30 def steps instance_steps end |
#total_steps_number ⇒ Object
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_delete ⇒ Object
92 93 94 |
# File 'lib/form_journey/controller.rb', line 92 def when_delete return yield if request.delete? end |
#when_get ⇒ Object
96 97 98 |
# File 'lib/form_journey/controller.rb', line 96 def when_get return yield if request.get? end |
#when_patch ⇒ Object
84 85 86 |
# File 'lib/form_journey/controller.rb', line 84 def when_patch return yield if request.patch? end |
#when_post ⇒ Object
80 81 82 |
# File 'lib/form_journey/controller.rb', line 80 def when_post return yield if request.post? end |
#when_post_or_patch ⇒ Object
88 89 90 |
# File 'lib/form_journey/controller.rb', line 88 def when_post_or_patch return yield if request.patch? || request.post? end |