module AASM::Persistence::DynamoidPersistence

def self.included(base)

def self.included(base)
  base.send(:include, AASM::Persistence::Base)
  base.send(:include, AASM::Persistence::DynamoidPersistence::InstanceMethods)
  base.after_initialize :aasm_ensure_initial_state
  # Because Dynamoid only use define_method to add attribute assignment method in Class.
  #
  # In AASM::Base.initialize, it redefines and calls super in this method without superclass method.
  # We override method_missing to solve this problem.
  #
  base.class_eval %Q(
    def method_missing(method_name, *arguments, &block)
      if (AASM::StateMachineStore.fetch(self.class, true).machine_names.map { |state_machine_name| self.class.aasm(state_machine_name).attribute_name.to_s + "=" }).include? method_name.to_s
        attribute_name = method_name.to_s.gsub("=", '')
        write_attribute(attribute_name.to_sym, *arguments)
      else
        super
      end
    end
  )
end