Module: AASM::Persistence::ActiveRecordPersistence::ClassMethods

Defined in:
lib/aasm/persistence/active_record_persistence.rb

Instance Method Summary collapse

Instance Method Details

#aasm_create_scope(state_machine_name, scope_name) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/aasm/persistence/active_record_persistence.rb', line 43

def aasm_create_scope(state_machine_name, scope_name)
  if ActiveRecord::VERSION::MAJOR >= 3
    conditions = { aasm(state_machine_name).attribute_name => scope_name.to_s }
    class_eval do
      scope scope_name, lambda { where(table_name => conditions) }
    end
  else
    conditions = {
      table_name => { aasm(state_machine_name).attribute_name => scope_name.to_s }
    }
    class_eval do
      named_scope scope_name, :conditions => conditions
    end
  end
end