blob: aebd03344aa1be64feda27b823077d131ba43372 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
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
|