Sha256: 9dfe9d00f4eec4d436bb411d808cee47c0b1098f0d2831cc29992a07400b7081
Contents?: true
Size: 791 Bytes
Versions: 8
Compression:
Stored size: 791 Bytes
Contents
module Stateflow module Persistence module ActiveRecord def self.install(base) 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 module InstanceMethods def load_from_persistence self.send machine.state_column.to_sym end def save_to_persistence(new_state) self.update_attribute(machine.state_column.to_sym, new_state) 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
8 entries across 8 versions & 1 rubygems