Sha256: bdd3feed71c299ebc5dd4ad2e69880054d82b5b2b2f291e2d30b1fa1bf7c3a45

Contents?: true

Size: 1.39 KB

Versions: 5

Compression:

Stored size: 1.39 KB

Contents

module CassandraObject
  module Model
    def column_family=(column_family)
      @column_family = column_family
    end

    def column_family
      @column_family ||= base_class.name.pluralize
    end

    def base_class
      class_of_active_record_descendant(self)
    end

    def config=(config)
      @@config = config.deep_symbolize_keys
    end

    def config
      @@config
    end

    def allow_filtering=(value)
      @allow_filtering = value
    end

    def allow_filtering
      @allow_filtering ||= false
    end

    def _key
      # todo only first key
      keys.tr('()','').split(',').first
    end

    def keys=(value)
      @keys = value
    end

    def keys
      @keys ||= '(key)'
    end

    private

    # Returns the class descending directly from ActiveRecord::Base or an
    # abstract class, if any, in the inheritance hierarchy.
    def class_of_active_record_descendant(klass)
      # klass

      if (klass == Base || klass.superclass == Base) || (klass == BaseSchemaless || klass.superclass == BaseSchemaless) || (klass == BaseSchema || klass.superclass == BaseSchema) || (klass == BaseSchemalessDynamic || klass.superclass == BaseSchemalessDynamic)
        klass
      elsif klass.superclass.nil?
        raise "#{name} doesn't belong in a hierarchy descending from CassandraObject"
      else
        class_of_active_record_descendant(klass.superclass)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
extendi-cassandra_object-1.0.6 lib/cassandra_object/model.rb
extendi-cassandra_object-1.0.5 lib/cassandra_object/model.rb
extendi-cassandra_object-1.0.4 lib/cassandra_object/model.rb
extendi-cassandra_object-1.0.1 lib/cassandra_object/model.rb
extendi-cassandra_object-1.0.0 lib/cassandra_object/model.rb