Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

The final extract method refactoring that tames the beast formerly known

as FSM#transition
  • Loading branch information...
commit 822a1a06d51796599af16c6d8ed5d3395c825653 1 parent 397cdaa
Joey Butler authored
Showing with 19 additions and 12 deletions.
  1. +19 −12 lib/celluloid/fsm.rb
View
31 lib/celluloid/fsm.rb
@@ -84,6 +84,24 @@ def attach(actor)
#
# Note: making additional state transitions will cancel delayed transitions
def transition(state_name, options = {})
+ new_state = validate_and_sanitize_new_state(state_name)
+ return unless new_state
+
+ if handle_delayed_transitions(new_state, options[:delay])
+ return @delayed_transition
+ end
+
+ transition_with_callbacks!(new_state)
+ end
+
+ # Immediate state transition with no sanity checks, or callbacks. "Dangerous!"
+ def transition!(state_name)
+ @state = state_name
+ end
+
+ protected
+
+ def validate_and_sanitize_new_state(state_name)
state_name = state_name.to_sym
return if current_state_name == state_name
@@ -100,20 +118,9 @@ def transition(state_name, options = {})
raise ArgumentError, "invalid state for #{self.class}: #{state_name}"
end
- if handle_delayed_transitions(new_state, options[:delay])
- return @delayed_transition
- end
-
- transition_with_callbacks!(new_state)
+ new_state
end
- # Immediate state transition with no sanity checks, or callbacks. "Dangerous!"
- def transition!(state_name)
- @state = state_name
- end
-
- protected
-
def transition_with_callbacks!(state_name)
transition! state_name.name
state_name.call(self)
Please sign in to comment.
Something went wrong with that request. Please try again.