module FormInput::StepMethods

Localize few step methods.

Additional methods used for multi-step form processing.

Public Class Methods

new( *args ) click to toggle source

Initialize new instance.

Calls superclass method
# 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

Public Instance Methods

accessible_step?( step = self.step ) click to toggle source

Test if given/current step is accessible.

# File lib/form_input/steps.rb, line 317
def accessible_step?( step = self.step )
  not inaccessible_step?( step )
end
accessible_steps() click to toggle source

Get already accessible steps, including the last accessed step.

# File lib/form_input/steps.rb, line 307
def accessible_steps
  steps - inaccessible_steps
end
bad_step?( step = self.step ) click to toggle source

Test if given/current step shall be displayed as incorrect.

# File lib/form_input/steps.rb, line 357
def bad_step?( step = self.step )
  incomplete_step?( step )
end
bad_steps() click to toggle source

Get steps which shall be displayed as incorrect.

# File lib/form_input/steps.rb, line 347
def bad_steps
  steps.select{ |step| bad_step?( step ) }
end
complete_step?( step = self.step ) click to toggle source

Test if given/current step is one of the complete steps.

# File lib/form_input/steps.rb, line 332
def complete_step?( step = self.step )
  finished_step?( step ) and correct_step?( step )
end
complete_steps() click to toggle source

Get correct finished steps. Includes finished steps without parameters.

# File lib/form_input/steps.rb, line 322
def complete_steps
  finished_steps.select{ |step| correct_step?( step ) }
end
correct_step?( step = self.step ) click to toggle source

Test if the current/given step has all data filled in correctly. Considered true for steps without parameters.

# File lib/form_input/steps.rb, line 250
def correct_step?( step = self.step )
  valid?( step_params( step ) )
end
correct_steps() click to toggle source

Get steps which have all data filled in correctly. Excludes steps without parameters.

# File lib/form_input/steps.rb, line 235
def correct_steps
  filter_steps{ |params| valid?( params ) }
end
current_params() click to toggle source

Get the parameters relevant for the current step.

# File lib/form_input/steps.rb, line 58
def current_params
  tagged_params( step )
end
disabled_step?( step = self.step ) click to toggle source

Test if given/current step has all parameters disabled. Considered false for steps without parameters.

# File lib/form_input/steps.rb, line 276
def disabled_step?( step = self.step )
  not enabled_step?( step )
end
disabled_steps() click to toggle source

Get steps with all parameters disabled. Excludes steps without parameters.

# 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 ) click to toggle source

Test if given/current step has some parameters enabled. Considered true for steps without parameters.

# 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() click to toggle source

Get steps with some parameters enabled. Excludes steps without parameters.

# 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 ) click to toggle source

Test if the current/given step has no parameters defined.

# File lib/form_input/steps.rb, line 166
def extra_step?( step = self.step )
  step_params( step ).empty?
end
extra_steps() click to toggle source

Get steps with no parameters defined.

# File lib/form_input/steps.rb, line 176
def extra_steps
  steps.select{ |step| extra_step?( step ) }
end
filled_step?( step = self.step ) click to toggle source

Test if given/current step has some data filled in. Considered true for steps without parameters.

# 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() click to toggle source

Get steps which have some data filled in. Excludes steps without parameters.

# File lib/form_input/steps.rb, line 214
def filled_steps
  filter_steps{ |params| params.any?{ |p| p.filled? } }
end
filter_steps() { |params| ... } click to toggle source

Filter steps by testing their corresponding parameters with given block. Excludes steps without parameters.

# 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 ) click to toggle source

Test if given/current step was visited or skipped over before.

# File lib/form_input/steps.rb, line 297
def finished_step?( step = self.step )
  not unfinished_step?( step )
end
finished_steps() click to toggle source

Get finished steps, those we have visited or skipped over before.

# File lib/form_input/steps.rb, line 286
def finished_steps
  steps - unfinished_steps
end
first_step( *args ) click to toggle source

Get first step, or first step among given list of steps, if any.

# 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 ) click to toggle source

Test if given/current step is the first step.

# File lib/form_input/steps.rb, line 124
def first_step?( step = self.step )
  step == first_step
end
form_steps() click to toggle source

Get hash mapping defined steps to their names. Note that this is never localized. See step_names instead.

# File lib/form_input/steps.rb, line 69
def form_steps
  self.class.form_steps
end
good_step?( step = self.step ) click to toggle source

Test if given/current step shall be displayed as correct.

# 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() click to toggle source

Get steps which shall be displayed as correct.

# File lib/form_input/steps.rb, line 342
def good_steps
  steps.select{ |step| good_step?( step ) }
end
inaccessible_step?( step = self.step ) click to toggle source

Test if given/current step is inaccessible.

# File lib/form_input/steps.rb, line 312
def inaccessible_step?( step = self.step )
  step_index( step ) > step_index( last )
end
inaccessible_steps() click to toggle source

Get yet inaccessible steps, excluding the last accessed step.

# File lib/form_input/steps.rb, line 302
def inaccessible_steps
  next_steps( last )
end
incomplete_step?( step = self.step ) click to toggle source

Test if given/current step is one of the incomplete steps.

# File lib/form_input/steps.rb, line 337
def incomplete_step?( step = self.step )
  finished_step?( step ) and incorrect_step?( step )
end
incomplete_steps() click to toggle source

Get incorrect finished steps. Excludes steps without parameters.

# File lib/form_input/steps.rb, line 327
def incomplete_steps
  finished_steps.select{ |step| incorrect_step?( step ) }
end
incorrect_step() click to toggle source

Get first step with invalid data, or nil if there is none.

# File lib/form_input/steps.rb, line 245
def incorrect_step
  incorrect_steps.first
end
incorrect_step?( step = self.step ) click to toggle source

Test if the current/given step has some invalid data filled in. Considered false for steps without parameters.

# File lib/form_input/steps.rb, line 255
def incorrect_step?( step = self.step )
  invalid?( step_params( step ) )
end
incorrect_steps() click to toggle source

Get steps which have some invalid data filled in. Excludes steps without parameters.

# File lib/form_input/steps.rb, line 240
def incorrect_steps
  filter_steps{ |params| invalid?( params ) }
end
last_step( *args ) click to toggle source

Get last step, or last step among given list of steps, if any.

# 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 ) click to toggle source

Test if given/current step is the last step.

# File lib/form_input/steps.rb, line 129
def last_step?( step = self.step )
  step == last_step
end
next_step( step = self.step ) click to toggle source

Get the next step, or nil if there is none.

# File lib/form_input/steps.rb, line 146
def next_step( step = self.step )
  next_steps( step ).first
end
next_step_name() click to toggle source

Get name of the next step, if any.

# File lib/form_input/steps.rb, line 156
def next_step_name
  step_name( next_step )
end
next_steps( step = self.step ) click to toggle source

Get steps after given/current step.

# 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 ) click to toggle source

Test if given/current step has no required parameters. Considered true for steps without parameters.

# File lib/form_input/steps.rb, line 209
def optional_step?( step = self.step )
  not required_step?( step )
end
optional_steps() click to toggle source

Get steps which have no required parameters. Excludes steps without parameters.

# File lib/form_input/steps.rb, line 199
def optional_steps
  filter_steps{ |params| params.none?{ |p| p.required? } }
end
other_params() click to toggle source

Get the parameters irrelevant for the current step.

# File lib/form_input/steps.rb, line 63
def other_params
  untagged_params( step )
end
previous_step( step = self.step ) click to toggle source

Get the previous step, or nil if there is none.

# File lib/form_input/steps.rb, line 151
def previous_step( step = self.step )
  previous_steps( step ).last
end
previous_step_name() click to toggle source

Get name of the previous step, if any.

# File lib/form_input/steps.rb, line 161
def previous_step_name
  step_name( previous_step )
end
previous_steps( step = self.step ) click to toggle source

Get steps before given/current step.

# File lib/form_input/steps.rb, line 134
def previous_steps( step = self.step )
  index = steps.index( step ) || 0
  steps.first( index )
end
raw_step_name( step = self.step )
Alias for: step_name
raw_step_names()
Alias for: step_names
regular_step?( step = self.step ) click to toggle source

Test if the current/given step has some parameters defined.

# File lib/form_input/steps.rb, line 171
def regular_step?( step = self.step )
  not extra_step?( step )
end
regular_steps() click to toggle source

Get steps with some parameters defined.

# File lib/form_input/steps.rb, line 181
def regular_steps
  steps.select{ |step| regular_step?( step ) }
end
required_step?( step = self.step ) click to toggle source

Test if given/current has some required parameters. Considered false for steps without parameters.

# File lib/form_input/steps.rb, line 204
def required_step?( step = self.step )
  step_params( step ).any?{ |p| p.required? }
end
required_steps() click to toggle source

Get steps which have required parameters. Excludes steps without parameters.

# File lib/form_input/steps.rb, line 194
def required_steps
  filter_steps{ |params| params.any?{ |p| p.required? } }
end
step_after?( step ) click to toggle source

Test if current step is after given step.

# File lib/form_input/steps.rb, line 101
def step_after?( step )
  step_index > step_index( step )
end
step_before?( step ) click to toggle source

Test if current step is before given step.

# File lib/form_input/steps.rb, line 96
def step_before?( step )
  step_index < step_index( step )
end
step_index( step = self.step ) click to toggle source

Get index of given/current step among all steps.

# 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 ) click to toggle source

Get name of current or given step, if any.

# 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
Also aliased as: raw_step_name
step_names() click to toggle source

Get hash of steps along with their names.

# 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
Also aliased as: raw_step_names
step_params( step ) click to toggle source

Get parameters relevant for given step.

# 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() click to toggle source

Get allowed form steps as list of symbols.

# File lib/form_input/steps.rb, line 74
def steps
  form_steps.keys
end
unfilled_step?( step = self.step ) click to toggle source

Test if given/current step has no data filled in. Considered false for steps without parameters.

# File lib/form_input/steps.rb, line 230
def unfilled_step?( step = self.step )
  not filled_step?( step )
end
unfilled_steps() click to toggle source

Get steps which have no data filled in. Excludes steps without parameters.

# 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 ) click to toggle source

Test if given/current step was not yet visited or was visited for the first time.

# 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() click to toggle source

Get unfinished steps, those we have not yet visited or visited for the first time.

# File lib/form_input/steps.rb, line 281
def unfinished_steps
  next_steps( seen )
end
unlock_steps() click to toggle source

Make all steps instantly available. Returns self for chaining.

# File lib/form_input/steps.rb, line 46
def unlock_steps
  self.last = self.seen = steps.last
  self
end