mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
removing extra spaces
This commit is contained in:
parent
27fc466e4f
commit
e593ec20d7
8 changed files with 31 additions and 31 deletions
22
lib/aasm.rb
22
lib/aasm.rb
|
@ -13,7 +13,7 @@ module AASM
|
||||||
|
|
||||||
class UndefinedState < RuntimeError
|
class UndefinedState < RuntimeError
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.included(base) #:nodoc:
|
def self.included(base) #:nodoc:
|
||||||
# TODO - need to ensure that a machine is being created because
|
# TODO - need to ensure that a machine is being created because
|
||||||
# AASM was either included or arrived at via inheritance. It
|
# AASM was either included or arrived at via inheritance. It
|
||||||
|
@ -36,11 +36,11 @@ module AASM
|
||||||
AASM::StateMachine[self].initial_state
|
AASM::StateMachine[self].initial_state
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def aasm_initial_state=(state)
|
def aasm_initial_state=(state)
|
||||||
AASM::StateMachine[self].initial_state = state
|
AASM::StateMachine[self].initial_state = state
|
||||||
end
|
end
|
||||||
|
|
||||||
def aasm_state(name, options={})
|
def aasm_state(name, options={})
|
||||||
sm = AASM::StateMachine[self]
|
sm = AASM::StateMachine[self]
|
||||||
sm.create_state(name, options)
|
sm.create_state(name, options)
|
||||||
|
@ -50,10 +50,10 @@ module AASM
|
||||||
aasm_current_state == name
|
aasm_current_state == name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def aasm_event(name, options = {}, &block)
|
def aasm_event(name, options = {}, &block)
|
||||||
sm = AASM::StateMachine[self]
|
sm = AASM::StateMachine[self]
|
||||||
|
|
||||||
unless sm.events.has_key?(name)
|
unless sm.events.has_key?(name)
|
||||||
sm.events[name] = AASM::SupportingClasses::Event.new(name, options, &block)
|
sm.events[name] = AASM::SupportingClasses::Event.new(name, options, &block)
|
||||||
end
|
end
|
||||||
|
@ -74,11 +74,11 @@ module AASM
|
||||||
def aasm_events
|
def aasm_events
|
||||||
AASM::StateMachine[self].events
|
AASM::StateMachine[self].events
|
||||||
end
|
end
|
||||||
|
|
||||||
def aasm_states_for_select
|
def aasm_states_for_select
|
||||||
AASM::StateMachine[self].states.map { |state| state.for_select }
|
AASM::StateMachine[self].states.map { |state| state.for_select }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Instance methods
|
# Instance methods
|
||||||
|
@ -129,10 +129,10 @@ module AASM
|
||||||
aasm_state_object_for_state(aasm_current_state).call_action(:exit, self)
|
aasm_state_object_for_state(aasm_current_state).call_action(:exit, self)
|
||||||
|
|
||||||
new_state = self.class.aasm_events[name].fire(self, *args)
|
new_state = self.class.aasm_events[name].fire(self, *args)
|
||||||
|
|
||||||
unless new_state.nil?
|
unless new_state.nil?
|
||||||
aasm_state_object_for_state(new_state).call_action(:enter, self)
|
aasm_state_object_for_state(new_state).call_action(:enter, self)
|
||||||
|
|
||||||
persist_successful = true
|
persist_successful = true
|
||||||
if persist
|
if persist
|
||||||
persist_successful = set_aasm_current_state_with_persistence(new_state)
|
persist_successful = set_aasm_current_state_with_persistence(new_state)
|
||||||
|
@ -141,7 +141,7 @@ module AASM
|
||||||
self.aasm_current_state = new_state
|
self.aasm_current_state = new_state
|
||||||
end
|
end
|
||||||
|
|
||||||
if persist_successful
|
if persist_successful
|
||||||
self.aasm_event_fired(self.aasm_current_state, new_state) if self.respond_to?(:aasm_event_fired)
|
self.aasm_event_fired(self.aasm_current_state, new_state) if self.respond_to?(:aasm_event_fired)
|
||||||
else
|
else
|
||||||
self.aasm_event_failed(name) if self.respond_to?(:aasm_event_failed)
|
self.aasm_event_failed(name) if self.respond_to?(:aasm_event_failed)
|
||||||
|
@ -152,7 +152,7 @@ module AASM
|
||||||
if self.respond_to?(:aasm_event_failed)
|
if self.respond_to?(:aasm_event_failed)
|
||||||
self.aasm_event_failed(name)
|
self.aasm_event_failed(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ module AASM
|
||||||
module SupportingClasses
|
module SupportingClasses
|
||||||
class Event
|
class Event
|
||||||
attr_reader :name, :success
|
attr_reader :name, :success
|
||||||
|
|
||||||
def initialize(name, options = {}, &block)
|
def initialize(name, options = {}, &block)
|
||||||
@name = name
|
@name = name
|
||||||
@success = options[:success]
|
@success = options[:success]
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
module AASM
|
module AASM
|
||||||
module Persistence
|
module Persistence
|
||||||
|
|
||||||
# Checks to see this class or any of it's superclasses inherit from
|
# Checks to see this class or any of it's superclasses inherit from
|
||||||
# ActiveRecord::Base and if so includes ActiveRecordPersistence
|
# ActiveRecord::Base and if so includes ActiveRecordPersistence
|
||||||
def self.set_persistence(base)
|
def self.set_persistence(base)
|
||||||
# Use a fancier auto-loading thingy, perhaps. When there are more persistence engines.
|
# Use a fancier auto-loading thingy, perhaps. When there are more persistence engines.
|
||||||
hierarchy = base.ancestors.map {|klass| klass.to_s}
|
hierarchy = base.ancestors.map {|klass| klass.to_s}
|
||||||
|
|
||||||
if hierarchy.include?("ActiveRecord::Base")
|
if hierarchy.include?("ActiveRecord::Base")
|
||||||
require File.join(File.dirname(__FILE__), 'persistence', 'active_record_persistence')
|
require File.join(File.dirname(__FILE__), 'persistence', 'active_record_persistence')
|
||||||
base.send(:include, AASM::Persistence::ActiveRecordPersistence)
|
base.send(:include, AASM::Persistence::ActiveRecordPersistence)
|
||||||
|
|
|
@ -10,10 +10,10 @@ module AASM
|
||||||
val = args.pop
|
val = args.pop
|
||||||
(@machines ||= {})[args] = val
|
(@machines ||= {})[args] = val
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :states, :events, :initial_state, :config
|
attr_accessor :states, :events, :initial_state, :config
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
@name = name
|
@name = name
|
||||||
@initial_state = nil
|
@initial_state = nil
|
||||||
|
|
|
@ -18,7 +18,7 @@ module AASM
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute(obj, *args)
|
def execute(obj, *args)
|
||||||
case @on_transition
|
case @on_transition
|
||||||
when Symbol, String
|
when Symbol, String
|
||||||
|
|
|
@ -54,11 +54,11 @@ describe AASM, '- class level definitions' do
|
||||||
it 'should define a class level aasm_event() method on its including class' do
|
it 'should define a class level aasm_event() method on its including class' do
|
||||||
Foo.should respond_to(:aasm_event)
|
Foo.should respond_to(:aasm_event)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should define a class level aasm_states() method on its including class' do
|
it 'should define a class level aasm_states() method on its including class' do
|
||||||
Foo.should respond_to(:aasm_states)
|
Foo.should respond_to(:aasm_states)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should define a class level aasm_states_for_select() method on its including class' do
|
it 'should define a class level aasm_states_for_select() method on its including class' do
|
||||||
Foo.should respond_to(:aasm_states_for_select)
|
Foo.should respond_to(:aasm_states_for_select)
|
||||||
end
|
end
|
||||||
|
@ -157,7 +157,7 @@ describe AASM, '- event firing with persistence' do
|
||||||
|
|
||||||
it 'should attempt to persist if aasm_write_state is defined' do
|
it 'should attempt to persist if aasm_write_state is defined' do
|
||||||
foo = Foo.new
|
foo = Foo.new
|
||||||
|
|
||||||
def foo.aasm_write_state
|
def foo.aasm_write_state
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ describe AASM, '- event firing with persistence' do
|
||||||
|
|
||||||
it 'should return true if aasm_write_state is defined and returns true' do
|
it 'should return true if aasm_write_state is defined and returns true' do
|
||||||
foo = Foo.new
|
foo = Foo.new
|
||||||
|
|
||||||
def foo.aasm_write_state(state)
|
def foo.aasm_write_state(state)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -178,7 +178,7 @@ describe AASM, '- event firing with persistence' do
|
||||||
|
|
||||||
it 'should return false if aasm_write_state is defined and returns false' do
|
it 'should return false if aasm_write_state is defined and returns false' do
|
||||||
foo = Foo.new
|
foo = Foo.new
|
||||||
|
|
||||||
def foo.aasm_write_state(state)
|
def foo.aasm_write_state(state)
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
@ -188,7 +188,7 @@ describe AASM, '- event firing with persistence' do
|
||||||
|
|
||||||
it "should not update the aasm_current_state if the write fails" do
|
it "should not update the aasm_current_state if the write fails" do
|
||||||
foo = Foo.new
|
foo = Foo.new
|
||||||
|
|
||||||
def foo.aasm_write_state
|
def foo.aasm_write_state
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
@ -217,7 +217,7 @@ describe AASM, '- event firing without persistence' do
|
||||||
|
|
||||||
it 'should attempt to persist if aasm_write_state is defined' do
|
it 'should attempt to persist if aasm_write_state is defined' do
|
||||||
foo = Foo.new
|
foo = Foo.new
|
||||||
|
|
||||||
def foo.aasm_write_state
|
def foo.aasm_write_state
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ describe ChetanPatil do
|
||||||
it 'should transition to specified next state (sleeping to showering)' do
|
it 'should transition to specified next state (sleeping to showering)' do
|
||||||
cp = ChetanPatil.new
|
cp = ChetanPatil.new
|
||||||
cp.wakeup! :showering
|
cp.wakeup! :showering
|
||||||
|
|
||||||
cp.aasm_current_state.should == :showering
|
cp.aasm_current_state.should == :showering
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@ describe AASM::SupportingClasses::State do
|
||||||
|
|
||||||
state.name.should == :astate
|
state.name.should == :astate
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should set the options and expose them as options' do
|
it 'should set the options and expose them as options' do
|
||||||
state = new_state
|
state = new_state
|
||||||
|
|
||||||
state.options.should == @options
|
state.options.should == @options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ describe AASM::SupportingClasses::State do
|
||||||
|
|
||||||
record = mock('record')
|
record = mock('record')
|
||||||
record.should_receive(:foobar)
|
record.should_receive(:foobar)
|
||||||
|
|
||||||
state.call_action(:entering, record)
|
state.call_action(:entering, record)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,7 +31,7 @@ describe AASM::SupportingClasses::StateTransition do
|
||||||
|
|
||||||
st.should_not == obj
|
st.should_not == obj
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should fail equality check if to are not the same' do
|
it 'should fail equality check if to are not the same' do
|
||||||
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
||||||
st = AASM::SupportingClasses::StateTransition.new(opts)
|
st = AASM::SupportingClasses::StateTransition.new(opts)
|
||||||
|
@ -58,7 +58,7 @@ describe AASM::SupportingClasses::StateTransition, '- when performing guard chec
|
||||||
|
|
||||||
obj = mock('object')
|
obj = mock('object')
|
||||||
obj.should_receive(:test)
|
obj.should_receive(:test)
|
||||||
|
|
||||||
st.perform(obj)
|
st.perform(obj)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ describe AASM::SupportingClasses::StateTransition, '- when performing guard chec
|
||||||
|
|
||||||
obj = mock('object')
|
obj = mock('object')
|
||||||
obj.should_receive(:test)
|
obj.should_receive(:test)
|
||||||
|
|
||||||
st.perform(obj)
|
st.perform(obj)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue