Sha256: 15d3217b908c851e4f3b7402a9812373ce33e90e5ad99966e91b0e9368ac481a

Contents?: true

Size: 1.89 KB

Versions: 5

Compression:

Stored size: 1.89 KB

Contents

require 'set'

require 'cassandra_object/log_subscriber'
require 'cassandra_object/types'
require 'cassandra_object/errors'

module CassandraObject
  class Base
    class << self
      def column_family=(column_family)
        @column_family = column_family
      end

      def column_family
        @column_family || name.pluralize
      end

      def base_class
        klass = self
        while klass.superclass != Base
          klass = klass.superclass
        end
        klass
      end
    end

    extend ActiveModel::Naming
    include ActiveModel::Conversion
    extend ActiveSupport::DescendantsTracker
    
    include Connection
    include Consistency
    include Identity
    include FinderMethods
    include Persistence
    include Batches
    include AttributeMethods
    include AttributeMethods::Dirty
    include AttributeMethods::Typecasting
    include Callbacks
    include Validations
    include Associations
    include Timestamps

    attr_reader :attributes

    include Serialization
    include Migrations
    include Mocking

    def initialize(attributes={})
      @key = attributes.delete(:key)
      @new_record = true
      @destroyed = false
      @attributes = {}
      self.attributes = attributes
      attribute_definitions.each do |attr, attribute_definition|
        unless attribute_exists?(attr)
          self.attributes[attr.to_s] = self.class.typecast_attribute(self, attr, nil)
        end
      end

      @schema_version = self.class.current_schema_version
    end

    def to_param
      id.to_s if persisted?
    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

ActiveSupport.run_load_hooks(:cassandra_object, CassandraObject::Base)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.10.2 lib/cassandra_object/base.rb
gotime-cassandra_object-2.10.1 lib/cassandra_object/base.rb
gotime-cassandra_object-2.10.0 lib/cassandra_object/base.rb
gotime-cassandra_object-2.9.2 lib/cassandra_object/base.rb
gotime-cassandra_object-2.9.1 lib/cassandra_object/base.rb