Module: AASM::Persistence::MongoidPersistence

Defined in:
lib/aasm/persistence/mongoid_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

before_validation :aasm_ensure_initial_state

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

class Foo
  include Mongoid::Document
  def aasm_write_state(state)
    "bar"
  end
  include AASM
end

class Foo
  include Mongoid::Document
  include AASM
  def aasm_write_state(state)
    "bar"
  end
end


32
33
34
35
36
37
38
39
# File 'lib/aasm/persistence/mongoid_persistence.rb', line 32

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

  base.after_initialize :aasm_ensure_initial_state
end