lib/stateflow.rb in stateflow-0.0.1 vs lib/stateflow.rb in stateflow-0.0.2

- old
+ new

@@ -1,13 +1,14 @@ module Stateflow def self.included(base) base.send :include, InstanceMethods + Stateflow::Persistence.set(base) base.extend ClassMethods end def self.persistence - @@persistence ||= "active_record" + @@persistence ||= :active_record end def self.persistence=(persistence) @@persistence = persistence end @@ -32,15 +33,16 @@ end end end module InstanceMethods - def current_state - @current_state ||= machine.initial_state + def current_state + @current_state ||= load_from_persistence.nil? ? machine.initial_state : machine.states[load_from_persistence.to_sym] end def current_state=(new_state) + save_to_persistence(new_state.name.to_s) @current_state = new_state end def machine self.class.machine @@ -56,6 +58,7 @@ autoload :Machine, 'stateflow/machine' autoload :State, 'stateflow/state' autoload :Event, 'stateflow/event' autoload :Transition, 'stateflow/transition' -end \ No newline at end of file + autoload :Persistence, 'stateflow/persistence' +end