Sha256: cd7a73f4337b054e8d3f677f87999c5f0f65535a8e82e844ce6b5bd79bcc402f

Contents?: true

Size: 861 Bytes

Versions: 1

Compression:

Stored size: 861 Bytes

Contents

module Cql::Model::SchemaMethods
  extend ::ActiveSupport::Concern

  def table_name
    self.class.table_name
  end

  def primary_key
    self.class.primary_key
  end

  def consistency
    self.class.consistency
  end

  module ClassMethods
    def table_name
      @table_name ||= self.model_name.plural
    end

    def columns
      @columns ||= {}
    end

    def consistency(consistency_value = nil)
      @consistency ||= consistency_value.nil? ? :quorum : consistency_value.to_sym
    end

    def primary_key(key_name = nil)
      @primary_key ||= key_name.nil? ? 'id' : key_name.to_s
    end

    def column(attribute_name, options = {})
      column_name = options[:column_name] || attribute_name

      @columns ||= {}
      @columns[column_name.to_sym] = {
        attribute_name: attribute_name.to_sym,
      }.merge(options)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cql_model-0.0.5 lib/cql/model/schema_methods.rb