class Stall::Checkout::Wizard
Attributes
cart[R]
Public Class Methods
from_route_key(key)
click to toggle source
# File lib/stall/checkout/wizard.rb, line 87 def self.from_route_key(key) Stall::Utils.try_load_constant( [key.underscore.camelize, 'CheckoutWizard'].join ) end
new(cart)
click to toggle source
# File lib/stall/checkout/wizard.rb, line 18 def initialize(cart) @cart = cart end
route_key()
click to toggle source
# File lib/stall/checkout/wizard.rb, line 83 def self.route_key name.gsub(/CheckoutWizard/, '').underscore.gsub('_', ' ').parameterize end
steps(*identifiers)
click to toggle source
# File lib/stall/checkout/wizard.rb, line 10 def self.steps(*identifiers) if identifiers.length > 0 self._steps = identifiers else _steps end end
Public Instance Methods
complete?()
click to toggle source
# File lib/stall/checkout/wizard.rb, line 56 def complete? step_index && step_index >= steps_count - 1 end
current_step()
click to toggle source
# File lib/stall/checkout/wizard.rb, line 37 def current_step Stall::Checkout::Step.for(current_step_name) end
current_step_name()
click to toggle source
# File lib/stall/checkout/wizard.rb, line 41 def current_step_name if step?(cart.state) cart.state else raise StepUndefinedError, "The current carte state #{ cart.state } does not exist " + "for the current #{ self.class.name } wizard, which has the " + "following steps : #{ steps.join(', ') }." end end
initialize_current_step(&block)
click to toggle source
# File lib/stall/checkout/wizard.rb, line 22 def initialize_current_step(&block) step = current_step.new(cart) # This block allows us to let inject controller-bound dependencies # into the step just after it's initialized block.call(step) if block if step.skip? validate_current_step! initialize_current_step(&block) else step end end
move_to_step!(target_step)
click to toggle source
# File lib/stall/checkout/wizard.rb, line 78 def move_to_step!(target_step) cart.state = target_step cart.save! end
next_step_name()
click to toggle source
# File lib/stall/checkout/wizard.rb, line 52 def next_step_name step_name_for(step_index + 1) if step_index && step_index < steps_count end
step_complete?(step)
click to toggle source
# File lib/stall/checkout/wizard.rb, line 64 def step_complete?(step) step_identifier = (Step === step ? step.identifier : step.to_sym) steps.index(cart.state) > steps.index(step_identifier) end
steps()
click to toggle source
# File lib/stall/checkout/wizard.rb, line 60 def steps @steps ||= self.class.steps end
steps_count()
click to toggle source
# File lib/stall/checkout/wizard.rb, line 69 def steps_count @steps_count ||= steps.length end
validate_current_step!()
click to toggle source
# File lib/stall/checkout/wizard.rb, line 73 def validate_current_step! cart.state = next_step_name cart.save! end
Private Instance Methods
step?(state)
click to toggle source
# File lib/stall/checkout/wizard.rb, line 103 def step?(state) steps.include?(state) end
step_index()
click to toggle source
# File lib/stall/checkout/wizard.rb, line 99 def step_index steps.index(cart.state) end
step_name_for(index)
click to toggle source
# File lib/stall/checkout/wizard.rb, line 95 def step_name_for(index) steps[index] end