Sha256: b7f5a768adea8b4b961e24d0117a1385e3a68b942fa2c1741a6dc7d57d44efad

Contents?: true

Size: 1.63 KB

Versions: 11

Compression:

Stored size: 1.63 KB

Contents

module Superstore
  module Core
    extend ActiveSupport::Concern

    module ClassMethods
      def inspect
        if self == Base
          super
        else
          attr_list = attribute_definitions.keys * ', '
          "#{super}(#{attr_list.truncate(140 * 1.7337)})"
        end
      end

      def initialize_generated_modules # :nodoc:
        generated_association_methods
      end

      def generated_association_methods
        @generated_association_methods ||= begin
          mod = const_set(:GeneratedAssociationMethods, Module.new)
          include mod
          mod
        end
      end

      def arel_table # :nodoc:
        @arel_table ||= Arel::Table.new(table_name, self)
      end

      def subclass_from_attributes?(attrs)
        false
      end
    end

    def initialize(attributes=nil)
      @new_record         = true
      @destroyed          = false
      @association_cache  = {}

      @attributes         = {}
      self.attributes = attributes || {}

      yield self if block_given?
    end

    def initialize_dup(other)
      @attributes = other.attributes
      @attributes['created_at'] = nil
      @attributes['updated_at'] = nil
      @attributes.delete(self.class.primary_key)
      @id = nil
      @new_record = true
      @destroyed = false
      @association_cache = {}
      super
    end

    def to_param
      id
    end

    def hash
      id.hash
    end

    def ==(comparison_object)
      comparison_object.equal?(self) ||
        (comparison_object.instance_of?(self.class) &&
          comparison_object.id == id)
    end

    def eql?(comparison_object)
      self == (comparison_object)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
superstore-2.4.4 lib/superstore/core.rb
superstore-2.4.3 lib/superstore/core.rb
superstore-2.4.2 lib/superstore/core.rb
superstore-2.4.1 lib/superstore/core.rb
superstore-2.4.0 lib/superstore/core.rb
superstore-2.3.0 lib/superstore/core.rb
superstore-2.2.0 lib/superstore/core.rb
superstore-2.1.3 lib/superstore/core.rb
superstore-2.1.2 lib/superstore/core.rb
superstore-2.1.1 lib/superstore/core.rb
superstore-2.1.0 lib/superstore/core.rb