slagyr/statemachine — pull request #11 by zombor (2012-12-10 20:07:32+00:00)
Title: Do not perform transitions if context method returns false

I have a requirement to abort a transition state change on certain conditions. I've patched the transition file, but didn't see any specs for that specific behavior.

Here's the sample code I'm using:

```ruby
require 'statemachine'

module Job
class StateMachine
def self.factory(job)
state_machine = Statemachine.build do
state :new do
event :expire, :expired, :expired?
event :accept, :booked
event :cancel, :canceled
end

context Context.new(job)
end

state_machine.context.statemachine = state_machine
state_machine.state = job.state

state_machine
end

class Context
attr_accessor :statemachine

def initialize(job)
@job = job
end

def expired?
if @job.start_date_time > Time.now.utc
return false
end
end
end
end
end

```

If the job start date is not in the past, it will not move to the expired state.