Sha256: d69df871aaaa349e2e9e2a4f704febb980b31d4d13b6b11aca0f09a2a2980939

Contents?: true

Size: 1.48 KB

Versions: 30

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

module Reek
  #
  # 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(new_options)
      options.merge!(new_options)
    end

    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+ in the given +context+.
    #
    # Raises an error if neither the context nor this config have a value for
    # the key.
    #
    def value(key, context)
      overrides_for(context).each { |conf| return conf[key] if conf.key?(key) }
      options.fetch(key)
    end

    private

    attr_reader :options
  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

    private

    attr_reader :hash
  end
end

Version data entries

30 entries across 28 versions & 2 rubygems

Version Path
reek-6.3.0 lib/reek/smell_configuration.rb
reek-6.2.0 lib/reek/smell_configuration.rb
reek-6.1.4 lib/reek/smell_configuration.rb
reek-6.1.3 lib/reek/smell_configuration.rb
reek-6.1.2 lib/reek/smell_configuration.rb
reek-6.1.1 lib/reek/smell_configuration.rb
reek-6.1.0 lib/reek/smell_configuration.rb
reek-6.0.6 lib/reek/smell_configuration.rb
reek-6.0.5 lib/reek/smell_configuration.rb
reek-6.0.4 lib/reek/smell_configuration.rb
reek-6.0.3 lib/reek/smell_configuration.rb
reek-6.0.2 lib/reek/smell_configuration.rb
reek-6.0.1 lib/reek/smell_configuration.rb
reek-6.0.0 lib/reek/smell_configuration.rb
reek-5.6.0 lib/reek/smell_configuration.rb
reek-5.5.0 lib/reek/smell_configuration.rb
reek-5.4.1 lib/reek/smell_configuration.rb
reek-5.4.0 lib/reek/smell_configuration.rb
reek-5.3.2 lib/reek/smell_configuration.rb
reek-5.3.1 lib/reek/smell_configuration.rb