Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # Testing the aasm gem to see how to get one aasm_event to decide
- # which state to transition into
- require 'rubygems'
- require 'aasm'
- class TestObject
- include AASM
- aasm_initial_state :active
- aasm_state :active, :enter => :make_active
- aasm_state :sold, :enter => :make_sold
- aasm_state :unsold, :enter => :make_unsold
- aasm_event :finish do
- transitions :to => :sold, :from => [:active], :guard => Proc.new {|a| a.reserve < a.price}
- transitions :to => :unsold, :from => [:active]
- end
- attr_accessor :price, :reserve, :name
- def initialize(name, price,reserve)
- @name = name
- @price = price
- @reserve = reserve
- end
- private
- def make_active
- puts "#{name} is now active!"
- end
- def make_sold
- puts "#{name} is now sold!"
- end
- def make_unsold
- puts "#{name} is now unsold!"
- end
- end
- sells = TestObject.new('sell',100,50)
- sells.finish
- nosell = TestObject.new('nosell',50,100)
- nosell.finish
Add Comment
Please, Sign In to add comment