treat plain Ruby reading and writing as kind of persistence (refactoring)
This commit is contained in:
parent
bde1780eb6
commit
b2dfee3209
|
@ -40,24 +40,6 @@ module AASM
|
|||
@aasm ||= AASM::InstanceBase.new(self)
|
||||
end
|
||||
|
||||
# may be overwritten by persistence mixins
|
||||
def aasm_read_state
|
||||
# all the following lines behave like @current_state ||= aasm.enter_initial_state
|
||||
current = aasm.instance_variable_get("@current_state")
|
||||
return current if current
|
||||
aasm.instance_variable_set("@current_state", aasm.enter_initial_state)
|
||||
end
|
||||
|
||||
# may be overwritten by persistence mixins
|
||||
def aasm_write_state(new_state)
|
||||
true
|
||||
end
|
||||
|
||||
# may be overwritten by persistence mixins
|
||||
def aasm_write_state_without_persistence(new_state)
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Takes args and a from state and removes the first
|
||||
|
|
|
@ -15,6 +15,9 @@ module AASM
|
|||
elsif hierarchy.include?("Sequel::Model")
|
||||
require_files_for(:sequel)
|
||||
base.send(:include, AASM::Persistence::SequelPersistence)
|
||||
else
|
||||
require File.join(File.dirname(__FILE__), 'persistence', 'plain_persistence')
|
||||
base.send(:include, AASM::Persistence::PlainPersistence)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
module AASM
|
||||
module Persistence
|
||||
module PlainPersistence
|
||||
|
||||
def aasm_read_state
|
||||
# all the following lines behave like @current_state ||= aasm.enter_initial_state
|
||||
current = aasm.instance_variable_get("@current_state")
|
||||
return current if current
|
||||
aasm.instance_variable_set("@current_state", aasm.enter_initial_state)
|
||||
end
|
||||
|
||||
# may be overwritten by persistence mixins
|
||||
def aasm_write_state(new_state)
|
||||
true
|
||||
end
|
||||
|
||||
# may be overwritten by persistence mixins
|
||||
def aasm_write_state_without_persistence(new_state)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue