Sha256: 1bf86eb6672a38a2eb3fa68c475b2fae6f228fba885f140588914238471e14de
Contents?: true
Size: 895 Bytes
Versions: 3
Compression:
Stored size: 895 Bytes
Contents
module Stateflow module Persistence module ActiveRecord def self.install(base) ActiveSupport::Deprecation.silence do base.respond_to?(:before_validation_on_create) ? base.before_validation_on_create(:ensure_initial_state) : base.before_validation(:ensure_initial_state, :on => :create) base.send :include, InstanceMethods end end module InstanceMethods def load_from_persistence self.send machine.state_column.to_sym end def save_to_persistence(new_state, options) self.send("#{machine.state_column}=".to_sym, new_state) self.save if options[:save] end def ensure_initial_state send("#{self.machine.state_column.to_s}=", self.current_state.name.to_s) if send(self.machine.state_column.to_s).blank? end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
stateflow-0.4.1 | lib/stateflow/persistence/active_record.rb |
stateflow-0.4.0 | lib/stateflow/persistence/active_record.rb |
stateflow-0.3.0 | lib/stateflow/persistence/active_record.rb |