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

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

Instance Method Summary collapse

Instance Method Details

#aasm_column(column_name = nil) ⇒ Object

Maps to the aasm_column in the database. Deafults to “aasm_state”. You can write:

create_table :foos do |t|
  t.string :name
  t.string :aasm_state
end

class Foo < ActiveRecord::Base
  include AASM
end

OR:

create_table :foos do |t|
  t.string :name
  t.string :status
end

class Foo < ActiveRecord::Base
  include AASM
  aasm_column :status
end

This method is both a getter and a setter



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/aasm/persistence/active_record_persistence.rb', line 82

def aasm_column(column_name=nil)
  if column_name
    AASM::StateMachine[self].config.column = column_name.to_sym
    # @aasm_column = column_name.to_sym
  else
    AASM::StateMachine[self].config.column ||= :aasm_state
    # @aasm_column ||= :aasm_state
  end
  # @aasm_column
  AASM::StateMachine[self].config.column
end

#calculate_in_state(state, *args) ⇒ Object



106
107
108
109
110
# File 'lib/aasm/persistence/active_record_persistence.rb', line 106

def calculate_in_state(state, *args)
  with_state_scope state do
    calculate(*args)
  end
end

#count_in_state(state, *args) ⇒ Object



100
101
102
103
104
# File 'lib/aasm/persistence/active_record_persistence.rb', line 100

def count_in_state(state, *args)
  with_state_scope state do
    count(*args)
  end
end

#find_in_state(number, state, *args) ⇒ Object



94
95
96
97
98
# File 'lib/aasm/persistence/active_record_persistence.rb', line 94

def find_in_state(number, state, *args)
  with_state_scope state do
    find(number, *args)
  end
end