Sha256: d6b764132a2d5fde90111265d28546c492652fca442035d8c33c28a9c2c4bb7c

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

module CassandraObject
  module Core
    extend ActiveSupport::Concern

    def initialize(attributes=nil)
      @new_record = true
      @destroyed = false
      @attributes = {}
      self.attributes = attributes || {}
      attribute_definitions.each_key do |attr|
        unless attribute_exists?(attr)
          @attributes[attr.to_s] = self.class.typecast_attribute(self, attr, nil)
        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 = @attributes.map do |col, definition| "#{col}: #{definition.type}" end * ', '
          "#{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

2 entries across 2 versions & 1 rubygems

Version Path
gotime-cassandra_object-4.10.5 lib/cassandra_object/core.rb
gotime-cassandra_object-4.10.4 lib/cassandra_object/core.rb