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:
parent
5bd5639704
commit
9e348d718b
2 changed files with 24 additions and 1 deletions
1
TODO
1
TODO
|
@ -4,7 +4,6 @@ Before Next Release:
|
||||||
* Add #aasm_next_state_for_event
|
* Add #aasm_next_state_for_event
|
||||||
* Add #aasm_next_states_for_event
|
* Add #aasm_next_states_for_event
|
||||||
|
|
||||||
|
|
||||||
Cool ideas from users:
|
Cool ideas from users:
|
||||||
|
|
||||||
* Support multiple state machines on one object (Chris Nelson)
|
* Support multiple state machines on one object (Chris Nelson)
|
||||||
|
|
|
@ -74,6 +74,30 @@ module AASM
|
||||||
@aasm_column
|
@aasm_column
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
Loading…
Reference in a new issue