Sha256: 26289055788b7ec4a7e3376fb5aa3757d94aefe494d0b4687ac1df0decf582eb

Contents?: true

Size: 930 Bytes

Versions: 11

Compression:

Stored size: 930 Bytes

Contents

module Superstore
  module Model
    extend ActiveSupport::Concern

    included do
      class_attribute :symbolized_config
      self.symbolized_config = {}
    end

    module ClassMethods
      def base_class
        class_of_active_record_descendant(self)
      end

      def config=(config)
        self.symbolized_config = config.deep_symbolize_keys
      end

      def config
        symbolized_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
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
superstore-2.4.4 lib/superstore/model.rb
superstore-2.4.3 lib/superstore/model.rb
superstore-2.4.2 lib/superstore/model.rb
superstore-2.4.1 lib/superstore/model.rb
superstore-2.4.0 lib/superstore/model.rb
superstore-2.3.0 lib/superstore/model.rb
superstore-2.2.0 lib/superstore/model.rb
superstore-2.1.3 lib/superstore/model.rb
superstore-2.1.2 lib/superstore/model.rb
superstore-2.1.1 lib/superstore/model.rb
superstore-2.1.0 lib/superstore/model.rb