lib/state_fu/persistence/base.rb in davidlee-state-fu-0.3.1 vs lib/state_fu/persistence/base.rb in davidlee-state-fu-0.10.0
- old
+ new
@@ -22,15 +22,17 @@
end
end
end
end
+ # define this method in subclasses to do any preparation
def self.prepare_field( klass, field_name )
- raise NotImplementedError # abstract method
+ Logger.warn("Abstract method in #{self}.prepare_field called. Override me!")
end
def initialize( binding, field_name )
+
@binding = binding
@field_name = field_name
@current_state = find_current_state()
if current_state.nil?
@@ -50,24 +52,24 @@
state_name = string.to_sym
state = machine.states[ state_name ] || raise( StateFu::InvalidStateName, string )
end
end
+ def reload
+ @current_state = find_current_state()
+ end
+
def machine
binding.machine
end
def object
binding.object
end
def klass
- object.class
+ binding.target
end
-
-# def method_name
-# binding.method_name
-# end
def current_state=( state )
raise(ArgumentError, state.inspect) unless state.is_a?(StateFu::State)
@current_state = state
persist!