Sha256: 096ea05ee5d6871609bade76f4a47a74e149a3684c99dfc5e09db487c7ed11af

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

module Superstore
  module Model
    def table_name=(table_name)
      @table_name = table_name
    end

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

    def column_family
      warn '`column_family` is deprecated & will be removed in superstore 2.0. Use `table_name` instead.'
      table_name
    end

    def column_family=(table_name)
      warn '`column_family=` is deprecated & will be removed in superstore 2.0. Use `table_name=` instead.'
      self.table_name = table_name
    end

    def base_class
      class_of_active_record_descendant(self)
    end

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

    def config
      @@config
    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)
      if klass == Base || klass.superclass == Base
        klass
      elsif klass.superclass.nil?
        raise "#{name} doesn't belong in a hierarchy descending from Superstore"
      else
        class_of_active_record_descendant(klass.superclass)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
superstore-1.1.0 lib/superstore/model.rb