Add .aasm_states method to get a list of all states for a class

This commit is contained in:
Scott Barron 2008-02-21 12:54:42 -05:00
parent 543ac695fd
commit 551503d12f
5 changed files with 16 additions and 4 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2006 Scott Barron
Copyright (c) 2008 Scott Barron
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@ -14,7 +14,6 @@ rescue Exception
nil
end
# Version
if `ruby -Ilib -rversion -e "print AASM::VERSION::STRING"` =~ /([0-9.]+)$/
CURRENT_VERSION = $1
else

1
TODO
View File

@ -4,7 +4,6 @@ Before Next Release:
* Add automatic persistence hooks for ActiveRecord classes
* Add #aasm_next_state_for_event
* Add #aasm_next_states_for_event
* Add .states
Cool ideas from users:

View File

@ -20,6 +20,7 @@ module AASM
alias :initial_state :aasm_initial_state=
def state(name, options={})
aasm_states << name unless aasm_states.include?(name)
self.aasm_initial_state = name unless self.aasm_initial_state
define_method("#{name.to_s}?") do
@ -28,7 +29,9 @@ module AASM
end
def event(name, &block)
aasm_events[name] = AASM::SupportingClasses::Event.new(name, &block)
unless aasm_events.has_key?(name)
aasm_events[name] = AASM::SupportingClasses::Event.new(name, &block)
end
define_method("#{name.to_s}!") do
new_state = self.class.aasm_events[name].fire(self)
@ -41,6 +44,10 @@ module AASM
end
end
def aasm_states
@aasm_states ||= []
end
def aasm_events
@aasm_events ||= {}
end

View File

@ -0,0 +1,7 @@
require File.join(File.dirname(__FILE__), 'conversation')
describe Conversation, 'description' do
it '.aasm_states should contain all of the states' do
Conversation.aasm_states.should == [:needs_attention, :read, :closed, :awaiting_response, :junk]
end
end