1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

Add .find_in_state, .count_in_state, .calculate_in_state back to AR layer

This commit is contained in:
Scott Barron 2008-05-29 13:10:31 -07:00
parent 5bd5639704
commit 9e348d718b
2 changed files with 24 additions and 1 deletions

1
TODO
View file

@ -4,7 +4,6 @@ Before Next Release:
* Add #aasm_next_state_for_event
* Add #aasm_next_states_for_event
Cool ideas from users:
* Support multiple state machines on one object (Chris Nelson)

View file

@ -74,6 +74,30 @@ module AASM
@aasm_column
end
def find_in_state(number, state, *args)
with_state_scope state do
find(number, *args)
end
end
def count_in_state(state, *args)
with_state_scope state do
count(*args)
end
end
def calculate_in_state(state, *args)
with_state_scope state do
calculate(*args)
end
end
protected
def with_state_scope(state)
with_scope :find => {:conditions => ["#{table_name}.#{aasm_column} = ?", state.to_s]} do
yield if block_given?
end
end
end
module InstanceMethods