Sha256: 36f6f387ff0e487d41aa54a9c6363b834350de040363f2d92bb99ef2ea5b5041

Contents?: true

Size: 899 Bytes

Versions: 21

Compression:

Stored size: 899 Bytes

Contents

class AutoShop < ActiveRecord::Base
  state_machine :state, :initial => 'available' do
    after_transition :from => 'available', :do => :increment_customers
    after_transition :from => 'busy', :do => :decrement_customers
    
    event :tow_vehicle do
      transition :to => 'busy', :from => 'available'
    end
    
    event :fix_vehicle do
      transition :to => 'available', :from => 'busy'
    end
  end
  
  # Is the Auto Shop available for new customers?
  def available?
    state == 'available'
  end
  
  # Is the Auto Shop currently not taking new customers?
  def busy?
    state == 'busy'
  end
  
  # Increments the number of customers in service
  def increment_customers
    update_attribute(:num_customers, num_customers + 1)
  end
  
  # Decrements the number of customers in service
  def decrement_customers
    update_attribute(:num_customers, num_customers - 1)
  end
end

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
spree-enriquez-0.9.4 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.9.4 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.9.3 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.9.2 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.9.1 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.9.0 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.8.4 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.8.5 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.4.1 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.4.0 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.5.0 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.5.1 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.6.0 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.7.0 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.7.1 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.8.0 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.8.1 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.8.2 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
spree-0.8.3 vendor/plugins/state_machine/test/app_root/app/models/auto_shop.rb
state_machine-0.3.1 test/app_root/app/models/auto_shop.rb