Sha256: eb2b61ff828c9fafa56d7b8ef984bfa0c1dbe594a9bcf9e4ea3c04a4324ed3f1

Contents?: true

Size: 1.08 KB

Versions: 15

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Esse
  class Index
    module ClassMethods
      # Set this to +true+ if this is an abstract class
      attr_accessor :abstract_class

      def abstract_class?
        return @abstract_class == true if defined?(@abstract_class)

        !index_name?
      end

      def inherited(subclass)
        super

        inherited_instance_variables.each do |variable_name, should_duplicate|
          if (variable_value = instance_variable_get(variable_name)) && should_duplicate
            value = case variable_value
            when Hash
              h = {}
              variable_value.each { |k, v| h[k] = v.dup }
              h
            else
              variable_value.dup
            end
          end
          subclass.instance_variable_set(variable_name, value)
        end
      end

      private

      def inherited_instance_variables
        {
          :@repo_hash => nil,
          :@setting => nil,
          :@mapping => nil,
          :@cluster_id => :dup,
          :@plugins => :dup,
        }
      end
    end

    extend ClassMethods
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
esse-0.4.0.rc4 lib/esse/index/inheritance.rb
esse-0.4.0.rc3 lib/esse/index/inheritance.rb
esse-0.4.0.rc2 lib/esse/index/inheritance.rb
esse-0.4.0.rc1 lib/esse/index/inheritance.rb
esse-0.3.5 lib/esse/index/inheritance.rb
esse-0.3.4 lib/esse/index/inheritance.rb
esse-0.3.3 lib/esse/index/inheritance.rb
esse-0.3.2 lib/esse/index/inheritance.rb
esse-0.3.1 lib/esse/index/inheritance.rb
esse-0.3.0 lib/esse/index/inheritance.rb
esse-0.2.6 lib/esse/index/inheritance.rb
esse-0.2.5 lib/esse/index/inheritance.rb
esse-0.2.4 lib/esse/index/inheritance.rb
esse-0.2.3 lib/esse/index/inheritance.rb
esse-0.2.2 lib/esse/index/inheritance.rb