module Stepper::ActiveRecordAdditions::InstanceMethods

Public Instance Methods

first_step?(step = stepper_current_step) click to toggle source

Use to check current step or given step is first step

first_step?("address")
# File lib/stepper/models/active_record_additions.rb, line 90
def first_step?(step = stepper_current_step)
  (step == stepper_steps.first) or stepper_current_step.blank? && step.blank?
end
last_step?(step = stepper_current_step) click to toggle source

Use to check current step or given step is last step

last_step?("address")
# File lib/stepper/models/active_record_additions.rb, line 84
def last_step?(step = stepper_current_step)
  step == self.stepper_steps.last
end
next_step() click to toggle source

returns next step of current step

# File lib/stepper/models/active_record_additions.rb, line 107
def next_step
  return stepper_steps.first if self.stepper_current_step.blank?
  return nil if self.last_step?
  stepper_steps[stepper_steps.index(stepper_current_step) + 1]
end
next_step!() click to toggle source

set next step as current step

# File lib/stepper/models/active_record_additions.rb, line 114
def next_step!
  self.stepper_current_step = self.next_step
  self
end
previous_step() click to toggle source

returns previous step of current step

# File lib/stepper/models/active_record_additions.rb, line 95
def previous_step
  return nil if (first_step? or stepper_current_step.blank?)
  stepper_steps[stepper_steps.index(stepper_current_step) - 1]
end
previous_step!() click to toggle source

set previous step as current step

# File lib/stepper/models/active_record_additions.rb, line 101
def previous_step!
  self.stepper_current_step = self.previous_step
  self
end
stepper_current_step() click to toggle source

returns name of current step

# File lib/stepper/models/active_record_additions.rb, line 73
def stepper_current_step
  self.send(self.stepper_current_step_column)
end
stepper_current_step=(step) click to toggle source

sets up name of current step

# File lib/stepper/models/active_record_additions.rb, line 78
def stepper_current_step=(step)
  self.send("#{self.stepper_current_step_column.to_s}=", step)
end
stepper_current_step_index() click to toggle source

returns index of current step in steps array

# File lib/stepper/models/active_record_additions.rb, line 68
def stepper_current_step_index
  stepper_steps.index(stepper_current_step)
end
stepper_steps() click to toggle source
# File lib/stepper/models/active_record_additions.rb, line 57
def stepper_steps
  self.stepper_options[:steps]
end

Protected Instance Methods

current_step_validation() click to toggle source

Executes validation methods for current step and all previous steps if its exists. You can set up what fields should be validated in methods for steps. For example:

def validate_description

self.validates_presence_of :name
self.validates_presence_of :desc

end

def validate_address

self.validates_presence_of :city
self.validates_presence_of :country
self.validates_presence_of :address

end

def validate_kind

self.validates_presence_of :kind

end

# File lib/stepper/models/active_record_additions.rb, line 139
def current_step_validation
  return if stepper_current_step.blank?
  for i in 0..stepper_current_step_index do
    self.send("validate_#{stepper_steps[i]}") if self.respond_to?("validate_#{stepper_steps[i]}", true)
  end
end