Sha256: 745d5507b183f09e36e81340af828f6bcc603544e6843b4437697b0521480f95

Contents?: true

Size: 865 Bytes

Versions: 5

Compression:

Stored size: 865 Bytes

Contents

# A valid example
class SlotMachine
  include DataMapper::Resource

  property :id, Serial
  property :power_on, Boolean, :default => false

  is :state_machine, :initial => :off, :column => :mode do
    state :off,
      :enter => :power_down,
      :exit  => :power_up
    state :idle
    state :spinning
    state :report_loss
    state :report_win
    state :pay_out

    event :pull_crank do
      transition :from => :idle,  :to => :spinning
    end

    event :turn_off do
      transition :from => :idle,  :to => :off
    end

    event :turn_on do
      transition :from => :off,   :to => :idle
    end
  end

  def initialize
    @log = []
    super
  end

  def power_up
    self.power_on = true
    @log << [:power_up, Time.now]
  end

  def power_down
    self.power_on = false
    @log << [:power_down, Time.now]
  end

end

SlotMachine.auto_migrate!

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dm-is-state_machine-0.9.10 spec/examples/slot_machine.rb
dm-is-state_machine-0.9.7 spec/examples/slot_machine.rb
dm-is-state_machine-0.9.11 spec/examples/slot_machine.rb
dm-is-state_machine-0.9.8 spec/examples/slot_machine.rb
dm-is-state_machine-0.9.9 spec/examples/slot_machine.rb