blob: aebd03344aa1be64feda27b823077d131ba43372 (
plain) (
tree)
|
|
module ActiveRecord
module StateMachine #:nodoc:
extend ActiveSupport::Concern
include ActiveModel::StateMachine
included do
before_validation :set_initial_state
validates_presence_of :state
end
protected
def write_state(state_machine, state)
update_attributes! :state => state.to_s
end
def read_state(state_machine)
self.state.to_sym
end
def set_initial_state
self.state ||= self.class.state_machine.initial_state.to_s
end
end
end
|