mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Add .aasm_states method to get a list of all states for a class
This commit is contained in:
parent
543ac695fd
commit
551503d12f
5 changed files with 16 additions and 4 deletions
|
@ -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
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|
1
Rakefile
1
Rakefile
|
@ -14,7 +14,6 @@ rescue Exception
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Version
|
|
||||||
if `ruby -Ilib -rversion -e "print AASM::VERSION::STRING"` =~ /([0-9.]+)$/
|
if `ruby -Ilib -rversion -e "print AASM::VERSION::STRING"` =~ /([0-9.]+)$/
|
||||||
CURRENT_VERSION = $1
|
CURRENT_VERSION = $1
|
||||||
else
|
else
|
||||||
|
|
1
TODO
1
TODO
|
@ -4,7 +4,6 @@ Before Next Release:
|
||||||
* Add automatic persistence hooks for ActiveRecord classes
|
* Add automatic persistence hooks for ActiveRecord classes
|
||||||
* Add #aasm_next_state_for_event
|
* Add #aasm_next_state_for_event
|
||||||
* Add #aasm_next_states_for_event
|
* Add #aasm_next_states_for_event
|
||||||
* Add .states
|
|
||||||
|
|
||||||
|
|
||||||
Cool ideas from users:
|
Cool ideas from users:
|
||||||
|
|
|
@ -20,6 +20,7 @@ module AASM
|
||||||
alias :initial_state :aasm_initial_state=
|
alias :initial_state :aasm_initial_state=
|
||||||
|
|
||||||
def state(name, options={})
|
def state(name, options={})
|
||||||
|
aasm_states << name unless aasm_states.include?(name)
|
||||||
self.aasm_initial_state = name unless self.aasm_initial_state
|
self.aasm_initial_state = name unless self.aasm_initial_state
|
||||||
|
|
||||||
define_method("#{name.to_s}?") do
|
define_method("#{name.to_s}?") do
|
||||||
|
@ -28,7 +29,9 @@ module AASM
|
||||||
end
|
end
|
||||||
|
|
||||||
def event(name, &block)
|
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
|
define_method("#{name.to_s}!") do
|
||||||
new_state = self.class.aasm_events[name].fire(self)
|
new_state = self.class.aasm_events[name].fire(self)
|
||||||
|
@ -41,6 +44,10 @@ module AASM
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def aasm_states
|
||||||
|
@aasm_states ||= []
|
||||||
|
end
|
||||||
|
|
||||||
def aasm_events
|
def aasm_events
|
||||||
@aasm_events ||= {}
|
@aasm_events ||= {}
|
||||||
end
|
end
|
||||||
|
|
7
spec/functional/conversation_spec.rb
Normal file
7
spec/functional/conversation_spec.rb
Normal 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
|
Loading…
Reference in a new issue