Sha256: afb277b0dccea42b3328137448050cdb296a0c4067cbc58f115ac685cca68ed0
Contents?: true
Size: 750 Bytes
Versions: 1
Compression:
Stored size: 750 Bytes
Contents
module BigMachine module ActiveRecord extend ActiveSupport::Concern included do class_attribute :state_attribute after_initialize :set_current_state_from_db end module ClassMethods def big_machine(options = {}) super options self.state_attribute = options[:state_attribute] || 'state' end end def set_current_state_from_db attribute = send state_attribute if attribute set_current_state(attribute.constantize) else self.class.set_initial_state_class end end def set_current_state(new_state_class) super(new_state_class) send "#{state_attribute}=", new_state_class.name end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
big_machine-1.1.0 | lib/big_machine/active_record.rb |