From 8697e97b7d7c18038466c62dd62c61a36a4036b4 Mon Sep 17 00:00:00 2001 From: Scott Barron Date: Tue, 8 Jan 2008 09:39:00 -0500 Subject: [PATCH] current_state -> aasm_current_state --- lib/aasm.rb | 14 +++++++++++--- lib/event.rb | 4 ++-- spec/aasm_spec.rb | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/aasm.rb b/lib/aasm.rb index 28e2195..ed6394b 100644 --- a/lib/aasm.rb +++ b/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 diff --git a/lib/event.rb b/lib/event.rb index 2be34f5..58d8300 100644 --- a/lib/event.rb +++ b/lib/event.rb @@ -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 diff --git a/spec/aasm_spec.rb b/spec/aasm_spec.rb index f81eebd..4d08561 100644 --- a/spec/aasm_spec.rb +++ b/spec/aasm_spec.rb @@ -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