Sha256: bc232ea9a31807edb304b8e42f7d939e42f90ea77fa697295dd19f9e466c1081

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module Modis
  module Model
    def self.included(base)
      base.instance_eval do
        include ActiveModel::Dirty
        include ActiveModel::Validations
        include ActiveModel::Serialization

        extend ActiveModel::Naming
        extend ActiveModel::Callbacks

        define_model_callbacks :save, :create, :update, :destroy

        include Modis::Errors
        include Modis::Transaction
        include Modis::Persistence
        include Modis::Finder
        include Modis::Attribute
        include Modis::Index

        base.extend(ClassMethods)
      end
    end

    module ClassMethods
      def inherited(child)
        super
        bootstrap_sti(self, child)
      end
    end

    def initialize(record = nil, options = {})
      apply_defaults
      set_sti_type
      assign_attributes(record) if record
      reset_changes

      return unless options.key?(:new_record)
      instance_variable_set('@new_record', options[:new_record])
    end

    def ==(other)
      super || other.instance_of?(self.class) && id.present? && other.id == id
    end
    alias_method :eql?, :==
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
modis-1.4.2 lib/modis/model.rb
modis-1.4.1-java lib/modis/model.rb
modis-1.4.1 lib/modis/model.rb
modis-1.4.0 lib/modis/model.rb