Permalink
Browse files

Add write_state_without_persistence implementation

  • Loading branch information...
1 parent 2a370a3 commit 370488c1dc69f077935050898f05fba0c9d04bd6 @zmillman zmillman committed Apr 30, 2012
Showing with 8 additions and 5 deletions.
  1. +8 −5 lib/active_model/transitions.rb
@@ -45,16 +45,19 @@ def reload(options = nil)
protected
def write_state(state_machine, state)
- ivar = state_machine.current_state_variable
prev_state = current_state(state_machine.name)
- instance_variable_set(ivar, state)
- self.state = state.to_s
+ write_state_without_persistence(state_machine, state)
save!
rescue ActiveRecord::RecordInvalid
- self.state = prev_state.to_s
- instance_variable_set(ivar, prev_state)
+ write_state_without_persistence(state_machine, prev_state)
raise
end
+
+ def write_state_without_persistence(state_machine, state)
+ ivar = state_machine.current_state_variable
+ instance_variable_set(ivar, state)
+ self.state = state.to_s
+ end
def read_state(state_machine)
self.state && self.state.to_sym

0 comments on commit 370488c

Please sign in to comment.