Module: FormInput::StepMethods
- Defined in:
- lib/form_input/r18n.rb,
lib/form_input/steps.rb
Overview
Additional methods used for multi-step form processing.
Instance Method Summary collapse
-
#accessible_step?(step = self.step) ⇒ Boolean
Test if given/current step is accessible.
-
#accessible_steps ⇒ Object
Get already accessible steps, including the last accessed step.
-
#bad_step?(step = self.step) ⇒ Boolean
Test if given/current step shall be displayed as incorrect.
-
#bad_steps ⇒ Object
Get steps which shall be displayed as incorrect.
-
#complete_step?(step = self.step) ⇒ Boolean
Test if given/current step is one of the complete steps.
-
#complete_steps ⇒ Object
Get correct finished steps.
-
#correct_step?(step = self.step) ⇒ Boolean
Test if the current/given step has all data filled in correctly.
-
#correct_steps ⇒ Object
Get steps which have all data filled in correctly.
-
#current_params ⇒ Object
Get the parameters relevant for the current step.
-
#disabled_step?(step = self.step) ⇒ Boolean
Test if given/current step has all parameters disabled.
-
#disabled_steps ⇒ Object
Get steps with all parameters disabled.
-
#enabled_step?(step = self.step) ⇒ Boolean
Test if given/current step has some parameters enabled.
-
#enabled_steps ⇒ Object
Get steps with some parameters enabled.
-
#extra_step?(step = self.step) ⇒ Boolean
Test if the current/given step has no parameters defined.
-
#extra_steps ⇒ Object
Get steps with no parameters defined.
-
#filled_step?(step = self.step) ⇒ Boolean
Test if given/current step has some data filled in.
-
#filled_steps ⇒ Object
Get steps which have some data filled in.
-
#filter_steps ⇒ Object
Filter steps by testing their corresponding parameters with given block.
-
#finished_step?(step = self.step) ⇒ Boolean
Test if given/current step was visited or skipped over before.
-
#finished_steps ⇒ Object
Get finished steps, those we have visited or skipped over before.
-
#first_step(*args) ⇒ Object
Get first step, or first step among given list of steps, if any.
-
#first_step?(step = self.step) ⇒ Boolean
Test if given/current step is the first step.
-
#form_steps ⇒ Object
Get hash mapping defined steps to their names.
-
#good_step?(step = self.step) ⇒ Boolean
Test if given/current step shall be displayed as correct.
-
#good_steps ⇒ Object
Get steps which shall be displayed as correct.
-
#inaccessible_step?(step = self.step) ⇒ Boolean
Test if given/current step is inaccessible.
-
#inaccessible_steps ⇒ Object
Get yet inaccessible steps, excluding the last accessed step.
-
#incomplete_step?(step = self.step) ⇒ Boolean
Test if given/current step is one of the incomplete steps.
-
#incomplete_steps ⇒ Object
Get incorrect finished steps.
-
#incorrect_step ⇒ Object
Get first step with invalid data, or nil if there is none.
-
#incorrect_step?(step = self.step) ⇒ Boolean
Test if the current/given step has some invalid data filled in.
-
#incorrect_steps ⇒ Object
Get steps which have some invalid data filled in.
-
#initialize(*args) ⇒ Object
Initialize new instance.
-
#last_step(*args) ⇒ Object
Get last step, or last step among given list of steps, if any.
-
#last_step?(step = self.step) ⇒ Boolean
Test if given/current step is the last step.
-
#next_step(step = self.step) ⇒ Object
Get the next step, or nil if there is none.
-
#next_step_name ⇒ Object
Get name of the next step, if any.
-
#next_steps(step = self.step) ⇒ Object
Get steps after given/current step.
-
#optional_step?(step = self.step) ⇒ Boolean
Test if given/current step has no required parameters.
-
#optional_steps ⇒ Object
Get steps which have no required parameters.
-
#other_params ⇒ Object
Get the parameters irrelevant for the current step.
-
#previous_step(step = self.step) ⇒ Object
Get the previous step, or nil if there is none.
-
#previous_step_name ⇒ Object
Get name of the previous step, if any.
-
#previous_steps(step = self.step) ⇒ Object
Get steps before given/current step.
-
#regular_step?(step = self.step) ⇒ Boolean
Test if the current/given step has some parameters defined.
-
#regular_steps ⇒ Object
Get steps with some parameters defined.
-
#required_step?(step = self.step) ⇒ Boolean
Test if given/current has some required parameters.
-
#required_steps ⇒ Object
Get steps which have required parameters.
-
#step_after?(step) ⇒ Boolean
Test if current step is after given step.
-
#step_before?(step) ⇒ Boolean
Test if current step is before given step.
-
#step_index(step = self.step) ⇒ Object
Get index of given/current step among all steps.
-
#step_name(step = self.step) ⇒ Object
(also: #raw_step_name)
Get name of current or given step, if any.
-
#step_names ⇒ Object
(also: #raw_step_names)
Get hash of steps along with their names, for use in a sidebar.
-
#step_params(step) ⇒ Object
Get parameters relevant for given step.
-
#steps ⇒ Object
Get allowed form steps as list of symbols.
-
#unfilled_step?(step = self.step) ⇒ Boolean
Test if given/current step has no data filled in.
-
#unfilled_steps ⇒ Object
Get steps which have no data filled in.
-
#unfinished_step?(step = self.step) ⇒ Boolean
Test if given/current step was not yet visited or was visited for the first time.
-
#unfinished_steps ⇒ Object
Get unfinished steps, those we have not yet visited or visited for the first time.
-
#unlock_steps ⇒ Object
Make all steps instantly available.
Instance Method Details
#accessible_step?(step = self.step) ⇒ Boolean
Test if given/current step is accessible.
317 318 319 |
# File 'lib/form_input/steps.rb', line 317 def accessible_step?( step = self.step ) not inaccessible_step?( step ) end |
#accessible_steps ⇒ Object
Get already accessible steps, including the last accessed step.
307 308 309 |
# File 'lib/form_input/steps.rb', line 307 def accessible_steps steps - inaccessible_steps end |
#bad_step?(step = self.step) ⇒ Boolean
Test if given/current step shall be displayed as incorrect.
357 358 359 |
# File 'lib/form_input/steps.rb', line 357 def bad_step?( step = self.step ) incomplete_step?( step ) end |
#bad_steps ⇒ Object
Get steps which shall be displayed as incorrect.
347 348 349 |
# File 'lib/form_input/steps.rb', line 347 def bad_steps steps.select{ |step| bad_step?( step ) } end |
#complete_step?(step = self.step) ⇒ Boolean
Test if given/current step is one of the complete steps.
332 333 334 |
# File 'lib/form_input/steps.rb', line 332 def complete_step?( step = self.step ) finished_step?( step ) and correct_step?( step ) end |
#complete_steps ⇒ Object
Get correct finished steps. Includes finished steps without parameters.
322 323 324 |
# File 'lib/form_input/steps.rb', line 322 def complete_steps finished_steps.select{ |step| correct_step?( step ) } end |
#correct_step?(step = self.step) ⇒ Boolean
Test if the current/given step has all data filled in correctly. Considered true for steps without parameters.
250 251 252 |
# File 'lib/form_input/steps.rb', line 250 def correct_step?( step = self.step ) valid?( step_params( step ) ) end |
#correct_steps ⇒ Object
Get steps which have all data filled in correctly. Excludes steps without parameters.
235 236 237 |
# File 'lib/form_input/steps.rb', line 235 def correct_steps filter_steps{ |params| valid?( params ) } end |
#current_params ⇒ Object
Get the parameters relevant for the current step.
58 59 60 |
# File 'lib/form_input/steps.rb', line 58 def current_params tagged_params( step ) end |
#disabled_step?(step = self.step) ⇒ Boolean
Test if given/current step has all parameters disabled. Considered false for steps without parameters.
276 277 278 |
# File 'lib/form_input/steps.rb', line 276 def disabled_step?( step = self.step ) not enabled_step?( step ) end |
#disabled_steps ⇒ Object
Get steps with all parameters disabled. Excludes steps without parameters.
265 266 267 |
# File 'lib/form_input/steps.rb', line 265 def disabled_steps filter_steps{ |params| params.all?{ |p| p.disabled? } } end |
#enabled_step?(step = self.step) ⇒ Boolean
Test if given/current step has some parameters enabled. Considered true for steps without parameters.
270 271 272 273 |
# File 'lib/form_input/steps.rb', line 270 def enabled_step?( step = self.step ) params = step_params( step ) params.empty? or params.any?{ |p| p.enabled? } end |
#enabled_steps ⇒ Object
Get steps with some parameters enabled. Excludes steps without parameters.
260 261 262 |
# File 'lib/form_input/steps.rb', line 260 def enabled_steps filter_steps{ |params| params.any?{ |p| p.enabled? } } end |
#extra_step?(step = self.step) ⇒ Boolean
Test if the current/given step has no parameters defined.
166 167 168 |
# File 'lib/form_input/steps.rb', line 166 def extra_step?( step = self.step ) step_params( step ).empty? end |
#extra_steps ⇒ Object
Get steps with no parameters defined.
176 177 178 |
# File 'lib/form_input/steps.rb', line 176 def extra_steps steps.select{ |step| extra_step?( step ) } end |
#filled_step?(step = self.step) ⇒ Boolean
Test if given/current step has some data filled in. Considered true for steps without parameters.
224 225 226 227 |
# File 'lib/form_input/steps.rb', line 224 def filled_step?( step = self.step ) params = step_params( step ) params.empty? or params.any?{ |p| p.filled? } end |
#filled_steps ⇒ Object
Get steps which have some data filled in. Excludes steps without parameters.
214 215 216 |
# File 'lib/form_input/steps.rb', line 214 def filled_steps filter_steps{ |params| params.any?{ |p| p.filled? } } end |
#filter_steps ⇒ Object
Filter steps by testing their corresponding parameters with given block. Excludes steps without parameters.
186 187 188 189 190 191 |
# File 'lib/form_input/steps.rb', line 186 def filter_steps steps.select do |step| params = step_params( step ) yield params unless params.empty? end end |
#finished_step?(step = self.step) ⇒ Boolean
Test if given/current step was visited or skipped over before.
297 298 299 |
# File 'lib/form_input/steps.rb', line 297 def finished_step?( step = self.step ) not unfinished_step?( step ) end |
#finished_steps ⇒ Object
Get finished steps, those we have visited or skipped over before.
286 287 288 |
# File 'lib/form_input/steps.rb', line 286 def finished_steps steps - unfinished_steps end |
#first_step(*args) ⇒ Object
Get first step, or first step among given list of steps, if any.
106 107 108 109 110 111 112 |
# File 'lib/form_input/steps.rb', line 106 def first_step( *args ) if args.empty? steps.first else args.flatten.compact.min_by{ |x| step_index( x ) } end end |
#first_step?(step = self.step) ⇒ Boolean
Test if given/current step is the first step.
124 125 126 |
# File 'lib/form_input/steps.rb', line 124 def first_step?( step = self.step ) step == first_step end |
#form_steps ⇒ Object
Get hash mapping defined steps to their names. Note that this is never localized. See step_names instead.
69 70 71 |
# File 'lib/form_input/steps.rb', line 69 def form_steps self.class.form_steps end |
#good_step?(step = self.step) ⇒ Boolean
Test if given/current step shall be displayed as correct.
352 353 354 |
# File 'lib/form_input/steps.rb', line 352 def good_step?( step = self.step ) complete_step?( step ) and filled_step?( step ) and regular_step?( step ) end |
#good_steps ⇒ Object
Get steps which shall be displayed as correct.
342 343 344 |
# File 'lib/form_input/steps.rb', line 342 def good_steps steps.select{ |step| good_step?( step ) } end |
#inaccessible_step?(step = self.step) ⇒ Boolean
Test if given/current step is inaccessible.
312 313 314 |
# File 'lib/form_input/steps.rb', line 312 def inaccessible_step?( step = self.step ) step_index( step ) > step_index( last ) end |
#inaccessible_steps ⇒ Object
Get yet inaccessible steps, excluding the last accessed step.
302 303 304 |
# File 'lib/form_input/steps.rb', line 302 def inaccessible_steps next_steps( last ) end |
#incomplete_step?(step = self.step) ⇒ Boolean
Test if given/current step is one of the incomplete steps.
337 338 339 |
# File 'lib/form_input/steps.rb', line 337 def incomplete_step?( step = self.step ) finished_step?( step ) and incorrect_step?( step ) end |
#incomplete_steps ⇒ Object
Get incorrect finished steps. Excludes steps without parameters.
327 328 329 |
# File 'lib/form_input/steps.rb', line 327 def incomplete_steps finished_steps.select{ |step| incorrect_step?( step ) } end |
#incorrect_step ⇒ Object
Get first step with invalid data, or nil if there is none.
245 246 247 |
# File 'lib/form_input/steps.rb', line 245 def incorrect_step incorrect_steps.first end |
#incorrect_step?(step = self.step) ⇒ Boolean
Test if the current/given step has some invalid data filled in. Considered false for steps without parameters.
255 256 257 |
# File 'lib/form_input/steps.rb', line 255 def incorrect_step?( step = self.step ) invalid?( step_params( step ) ) end |
#incorrect_steps ⇒ Object
Get steps which have some invalid data filled in. Excludes steps without parameters.
240 241 242 |
# File 'lib/form_input/steps.rb', line 240 def incorrect_steps filter_steps{ |params| invalid?( params ) } end |
#initialize(*args) ⇒ Object
Initialize new instance.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/form_input/steps.rb', line 31 def initialize( *args ) super self.seen = last_step( seen, step ) self.step ||= steps.first self.next ||= step self.last ||= step if correct_step? self.step = self.next self.seen = last_step( seen, previous_step( step ) ) end self.last = last_step( step, last ) end |
#last_step(*args) ⇒ Object
Get last step, or last step among given list of steps, if any.
115 116 117 118 119 120 121 |
# File 'lib/form_input/steps.rb', line 115 def last_step( *args ) if args.empty? steps.last else args.flatten.compact.max_by{ |x| step_index( x ) } end end |
#last_step?(step = self.step) ⇒ Boolean
Test if given/current step is the last step.
129 130 131 |
# File 'lib/form_input/steps.rb', line 129 def last_step?( step = self.step ) step == last_step end |
#next_step(step = self.step) ⇒ Object
Get the next step, or nil if there is none.
146 147 148 |
# File 'lib/form_input/steps.rb', line 146 def next_step( step = self.step ) next_steps( step ).first end |
#next_step_name ⇒ Object
Get name of the next step, if any.
156 157 158 |
# File 'lib/form_input/steps.rb', line 156 def next_step_name step_name( next_step ) end |
#next_steps(step = self.step) ⇒ Object
Get steps after given/current step.
140 141 142 143 |
# File 'lib/form_input/steps.rb', line 140 def next_steps( step = self.step ) index = steps.index( step ) || -1 steps[ index + 1 .. -1 ] end |
#optional_step?(step = self.step) ⇒ Boolean
Test if given/current step has no required parameters. Considered true for steps without parameters.
209 210 211 |
# File 'lib/form_input/steps.rb', line 209 def optional_step?( step = self.step ) not required_step?( step ) end |
#optional_steps ⇒ Object
Get steps which have no required parameters. Excludes steps without parameters.
199 200 201 |
# File 'lib/form_input/steps.rb', line 199 def optional_steps filter_steps{ |params| params.none?{ |p| p.required? } } end |
#other_params ⇒ Object
Get the parameters irrelevant for the current step.
63 64 65 |
# File 'lib/form_input/steps.rb', line 63 def other_params untagged_params( step ) end |
#previous_step(step = self.step) ⇒ Object
Get the previous step, or nil if there is none.
151 152 153 |
# File 'lib/form_input/steps.rb', line 151 def previous_step( step = self.step ) previous_steps( step ).last end |
#previous_step_name ⇒ Object
Get name of the previous step, if any.
161 162 163 |
# File 'lib/form_input/steps.rb', line 161 def previous_step_name step_name( previous_step ) end |
#previous_steps(step = self.step) ⇒ Object
Get steps before given/current step.
134 135 136 137 |
# File 'lib/form_input/steps.rb', line 134 def previous_steps( step = self.step ) index = steps.index( step ) || 0 steps.first( index ) end |
#regular_step?(step = self.step) ⇒ Boolean
Test if the current/given step has some parameters defined.
171 172 173 |
# File 'lib/form_input/steps.rb', line 171 def regular_step?( step = self.step ) not extra_step?( step ) end |
#regular_steps ⇒ Object
Get steps with some parameters defined.
181 182 183 |
# File 'lib/form_input/steps.rb', line 181 def regular_steps steps.select{ |step| regular_step?( step ) } end |
#required_step?(step = self.step) ⇒ Boolean
Test if given/current has some required parameters. Considered false for steps without parameters.
204 205 206 |
# File 'lib/form_input/steps.rb', line 204 def required_step?( step = self.step ) step_params( step ).any?{ |p| p.required? } end |
#required_steps ⇒ Object
Get steps which have required parameters. Excludes steps without parameters.
194 195 196 |
# File 'lib/form_input/steps.rb', line 194 def required_steps filter_steps{ |params| params.any?{ |p| p.required? } } end |
#step_after?(step) ⇒ Boolean
Test if current step is after given step.
101 102 103 |
# File 'lib/form_input/steps.rb', line 101 def step_after?( step ) step_index > step_index( step ) end |
#step_before?(step) ⇒ Boolean
Test if current step is before given step.
96 97 98 |
# File 'lib/form_input/steps.rb', line 96 def step_before?( step ) step_index < step_index( step ) end |
#step_index(step = self.step) ⇒ Object
Get index of given/current step among all steps.
91 92 93 |
# File 'lib/form_input/steps.rb', line 91 def step_index( step = self.step ) steps.index( step ) or fail( ArgumentError, "invalid step name #{step}" ) end |
#step_name(step = self.step) ⇒ Object Also known as: raw_step_name
Get name of current or given step, if any.
91 92 93 94 95 |
# File 'lib/form_input/r18n.rb', line 91 def step_name( step = self.step ) name = raw_step_name( step ) name = ( ft.steps[ step ] | name ).to_s if r18n and name name end |
#step_names ⇒ Object Also known as: raw_step_names
Get hash of steps along with their names, for use in a sidebar.
98 99 100 101 102 |
# File 'lib/form_input/r18n.rb', line 98 def step_names hash = raw_step_names hash = Hash[ hash.map{ |k,v| [ k, ( ft.steps[ k ] | v ).to_s ] } ] if r18n hash end |
#step_params(step) ⇒ Object
Get parameters relevant for given step.
52 53 54 55 |
# File 'lib/form_input/steps.rb', line 52 def step_params( step ) fail( ArgumentError, "invalid step name #{step}" ) unless form_steps.key?( step ) tagged_params( step ) end |
#steps ⇒ Object
Get allowed form steps as list of symbols.
74 75 76 |
# File 'lib/form_input/steps.rb', line 74 def steps form_steps.keys end |
#unfilled_step?(step = self.step) ⇒ Boolean
Test if given/current step has no data filled in. Considered false for steps without parameters.
230 231 232 |
# File 'lib/form_input/steps.rb', line 230 def unfilled_step?( step = self.step ) not filled_step?( step ) end |
#unfilled_steps ⇒ Object
Get steps which have no data filled in. Excludes steps without parameters.
219 220 221 |
# File 'lib/form_input/steps.rb', line 219 def unfilled_steps filter_steps{ |params| params.none?{ |p| p.filled? } } end |
#unfinished_step?(step = self.step) ⇒ Boolean
Test if given/current step was not yet visited or was visited for the first time.
291 292 293 294 |
# File 'lib/form_input/steps.rb', line 291 def unfinished_step?( step = self.step ) index = seen ? step_index( seen ) : -1 step_index( step ) > index end |
#unfinished_steps ⇒ Object
Get unfinished steps, those we have not yet visited or visited for the first time.
281 282 283 |
# File 'lib/form_input/steps.rb', line 281 def unfinished_steps next_steps( seen ) end |
#unlock_steps ⇒ Object
Make all steps instantly available. Returns self for chaining.
46 47 48 49 |
# File 'lib/form_input/steps.rb', line 46 def unlock_steps self.last = self.seen = steps.last self end |