mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
current_state -> aasm_current_state
This commit is contained in:
parent
053e9c7eee
commit
8697e97b7d
3 changed files with 15 additions and 7 deletions
14
lib/aasm.rb
14
lib/aasm.rb
|
@ -20,7 +20,7 @@ module AASM
|
|||
|
||||
def state(name, options={})
|
||||
define_method("#{name.to_s}?") do
|
||||
current_state == name
|
||||
aasm_current_state == name
|
||||
end
|
||||
self.aasm_initial_state = name unless self.aasm_initial_state
|
||||
end
|
||||
|
@ -28,7 +28,7 @@ module AASM
|
|||
def event(name, &block)
|
||||
define_method("#{name.to_s}!") do
|
||||
new_state = self.class.events[name].fire(self)
|
||||
@aasm_current_state = new_state
|
||||
self.aasm_current_state = new_state
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -42,7 +42,15 @@ module AASM
|
|||
end
|
||||
end
|
||||
|
||||
def current_state
|
||||
def aasm_current_state
|
||||
@aasm_current_state || self.class.aasm_initial_state
|
||||
end
|
||||
|
||||
private
|
||||
def aasm_current_state=(state)
|
||||
@aasm_current_state = state
|
||||
if self.respond_to?(:aasm_after_update) || self.private_methods.include?('aasm_after_update')
|
||||
aasm_after_update
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,11 +12,11 @@ module AASM
|
|||
end
|
||||
|
||||
def fire(obj)
|
||||
transitions = @transitions.select { |t| t.from == obj.current_state }
|
||||
transitions = @transitions.select { |t| t.from == obj.aasm_current_state }
|
||||
if transitions.size == 0
|
||||
raise AASM::InvalidTransition
|
||||
else
|
||||
transitions.first.to
|
||||
transitions.first.to # Should be performing here - but what's involved
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ describe AASM, '- initial states' do
|
|||
end
|
||||
|
||||
it 'should set the initial state' do
|
||||
@foo.current_state.should == :open
|
||||
@foo.aasm_current_state.should == :open
|
||||
end
|
||||
|
||||
it '#open? should be initially true' do
|
||||
|
@ -72,6 +72,6 @@ describe AASM, '- initial states' do
|
|||
end
|
||||
|
||||
it 'should use the first state defined if no initial state is given' do
|
||||
@bar.current_state.should == :read
|
||||
@bar.aasm_current_state.should == :read
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue