diff --git a/TODO b/TODO index 0b146c4..d016188 100644 --- a/TODO +++ b/TODO @@ -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) diff --git a/lib/persistence/active_record_persistence.rb b/lib/persistence/active_record_persistence.rb index 9488143..a44b237 100644 --- a/lib/persistence/active_record_persistence.rb +++ b/lib/persistence/active_record_persistence.rb @@ -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