Sha256: 76b80445ad6301efd15c6c90fcc64b71a5da65b7f7457706b0270a6052cdd237
Contents?: true
Size: 870 Bytes
Versions: 1
Compression:
Stored size: 870 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 send machine.state_column.to_sym end def save_to_persistence(new_state, options = {}) send("#{machine.state_column}=".to_sym, new_state) save if options[:save] end def ensure_initial_state send("#{machine.state_column.to_s}=", current_state.name.to_s) if send(machine.state_column.to_s).blank? end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stateflow-0.4.2 | lib/stateflow/persistence/active_record.rb |