Module: AASM::Persistence::ActiveRecordPersistence

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

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This method:

  • extends the model with ClassMethods

  • includes InstanceMethods

Adds

after_initialize :aasm_ensure_initial_state

As a result, it doesn't matter when you define your methods - the following 2 are equivalent

class Foo < ActiveRecord::Base
  def aasm_write_state(state)
    "bar"
  end
  include AASM
end

class Foo < ActiveRecord::Base
  include AASM
  def aasm_write_state(state)
    "bar"
  end
end

30
31
32
33
34
35
36
37
38
39
40
# File 'lib/aasm/persistence/active_record_persistence.rb', line 30

def self.included(base)
  base.send(:include, AASM::Persistence::Base)
  base.send(:include, AASM::Persistence::ORM)
  base.send(:include, AASM::Persistence::ActiveRecordPersistence::InstanceMethods)
  base.extend AASM::Persistence::ActiveRecordPersistence::ClassMethods

  base.after_initialize :aasm_ensure_initial_state

  # ensure state is in the list of states
  base.validate :aasm_validate_states
end