Sha256: bfbb3d07b9033099f93ce7aa74180eb56a130690a2d85c0e7a862690d96329f6

Contents?: true

Size: 1.54 KB

Versions: 18

Compression:

Stored size: 1.54 KB

Contents

module Reek
  module Core
    #
    # Represents a single set of configuration options for a smell detector
    #
    class SmellConfiguration
      # The name of the config field that specifies whether a smell is
      # enabled. Set to +true+ or +false+.
      ENABLED_KEY = 'enabled'

      # The name of the config field that sets scope-specific overrides
      # for other values in the current smell detector's configuration.
      OVERRIDES_KEY = 'overrides'

      def initialize(hash)
        @options = hash
      end

      def merge!(options)
        @options.merge!(options)
      end

      #
      # Is this smell detector active?
      #--
      #  SMELL: Getter
      def enabled?
        @options[ENABLED_KEY]
      end

      def overrides_for(context)
        Overrides.new(@options.fetch(OVERRIDES_KEY, {})).for_context(context)
      end

      # Retrieves the value, if any, for the given +key+.
      #
      # Returns +fall_back+ if this config has no value for the key.
      #
      def value(key, context, fall_back)
        overrides_for(context).each { |conf| return conf[key] if conf.key?(key) }
        @options.fetch(key, fall_back)
      end
    end

    #
    # A set of context-specific overrides for smell detectors.
    #
    class Overrides
      def initialize(hash)
        @hash = hash
      end

      # Find any overrides that match the supplied context
      def for_context(context)
        contexts = @hash.keys.select { |ckey| context.matches?([ckey]) }
        contexts.map { |exc| @hash[exc] }
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
reek-2.2.1 lib/reek/core/smell_configuration.rb
reek-2.2.0 lib/reek/core/smell_configuration.rb
reek-2.1.0 lib/reek/core/smell_configuration.rb
reek-2.0.4 lib/reek/core/smell_configuration.rb
reek-2.0.3 lib/reek/core/smell_configuration.rb
reek-2.0.2 lib/reek/core/smell_configuration.rb
reek-2.0.1 lib/reek/core/smell_configuration.rb
reek-2.0.0 lib/reek/core/smell_configuration.rb
reek-1.6.6 lib/reek/core/smell_configuration.rb
reek-1.6.5 lib/reek/core/smell_configuration.rb
reek-1.6.4 lib/reek/core/smell_configuration.rb
reek-1.6.3 lib/reek/core/smell_configuration.rb
reek-1.6.2 lib/reek/core/smell_configuration.rb
reek-1.6.1 lib/reek/core/smell_configuration.rb
reek-1.6.0 lib/reek/core/smell_configuration.rb
reek-1.5.1 lib/reek/core/smell_configuration.rb
reek-1.5.0 lib/reek/core/smell_configuration.rb
reek-1.4.0 lib/reek/core/smell_configuration.rb