Sha256: b4876814b2e0eff32add8d4ff37d65930493f90278e80902b38e3c5aea24f063

Contents?: true

Size: 1.29 KB

Versions: 16

Compression:

Stored size: 1.29 KB

Contents

module Superstore
  module Core
    extend ActiveSupport::Concern

    def initialize(attributes=nil)
      @new_record = true
      @destroyed = false
      @attributes = {}
      self.attributes = attributes || {}
      attribute_definitions.each_value do |definition|
        unless definition.default.nil? || attribute_exists?(definition.name)
          @attributes[definition.name] = definition.default
        end
      end

      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
      super
    end

    def to_param
      id
    end

    def hash
      id.hash
    end

    module ClassMethods
      def inspect
        if self == Base
          super
        else
          attr_list = attribute_definitions.keys * ', '
          "#{super}(#{attr_list.truncate(140 * 1.7337)})"
        end
      end
    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

16 entries across 16 versions & 1 rubygems

Version Path
superstore-1.2.0 lib/superstore/core.rb
superstore-1.1.4 lib/superstore/core.rb
superstore-1.1.3 lib/superstore/core.rb
superstore-1.1.2 lib/superstore/core.rb
superstore-1.1.1 lib/superstore/core.rb
superstore-1.1.0 lib/superstore/core.rb
superstore-1.0.12 lib/superstore/core.rb
superstore-1.0.11 lib/superstore/core.rb
superstore-1.0.10 lib/superstore/core.rb
superstore-1.0.9 lib/superstore/core.rb
superstore-1.0.8 lib/superstore/core.rb
superstore-1.0.7 lib/superstore/core.rb
superstore-1.0.6 lib/superstore/core.rb
superstore-1.0.5 lib/superstore/core.rb
superstore-1.0.4 lib/superstore/core.rb
superstore-1.0.3 lib/superstore/core.rb