Sha256: 32ec2856224698e105afbef21ede3d5180ea62cfc9c90d5c40baa6fa8d152b6d

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 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_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 get_cql_response
      self.class.cql_response.find(self.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

3 entries across 3 versions & 1 rubygems

Version Path
extendi-cassandra_object-1.0.4 lib/cassandra_object/core.rb
extendi-cassandra_object-1.0.1 lib/cassandra_object/core.rb
extendi-cassandra_object-1.0.0 lib/cassandra_object/core.rb