Skip to content
Browse files

Merge pull request #11 from sittercity/master

Do not perform transitions if context method returns false
  • Loading branch information...
2 parents 50d85d2 + 945a990 commit e376ca787187f1746f327d52d324dc39678e9311 @slagyr committed Dec 13, 2012
Showing with 14 additions and 7 deletions.
  1. +12 −5 lib/statemachine/transition.rb
  2. +2 −2 spec/spec_helper.rb
View
17 lib/statemachine/transition.rb
@@ -17,12 +17,19 @@ def invoke(origin, statemachine, args)
exits, entries = exits_and_entries(origin, destination)
exits.each { |exited_state| exited_state.exit(args) }
- origin.statemachine.invoke_action(@action, args, "transition action from #{origin} invoked by '#{@event}' event") if @action
+ if @action
+ result = origin.statemachine.invoke_action(@action, args, "transition action from #{origin} invoked by '#{@event}' event") if @action
+ transition = !(result === false)
+ else
+ transition = true
+ end
- terminal_state = entries.last
- terminal_state.activate if terminal_state
+ if transition
+ terminal_state = entries.last
+ terminal_state.activate if terminal_state
- entries.each { |entered_state| entered_state.enter(args) }
+ entries.each { |entered_state| entered_state.enter(args) }
+ end
end
def exits_and_entries(origin, destination)
@@ -61,4 +68,4 @@ def entries_to_destination(exit_state, destination)
end
-end
+end
View
4 spec/spec_helper.rb
@@ -33,12 +33,12 @@ def create_turnstile
@alarm_status = false
@thankyou_status = false
@lock = "@locked = true"
- @unlock = "@locked = false"
+ @unlock = "@locked = false; nil"
@alarm = "@alarm_status = true"
@thankyou = "@thankyou_status = true"
@sm = Statemachine.build do
- trans :locked, :coin, :unlocked, "@locked = false"
+ trans :locked, :coin, :unlocked, "@locked = false; nil"
trans :unlocked, :pass, :locked, "@locked = true"
trans :locked, :pass, :locked, "@alarm_status = true"
trans :unlocked, :coin, :locked, "@thankyou_status = true"

0 comments on commit e376ca7

Please sign in to comment.
Something went wrong with that request. Please try again.