Class: Reek::SmellConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/reek/smell_configuration.rb

Overview

Represents a single set of configuration options for a smell detector

Constant Summary collapse

ENABLED_KEY =

The name of the config field that specifies whether a smell is enabled. Set to true or false.

'enabled'
OVERRIDES_KEY =

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

'overrides'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ SmellConfiguration

Returns a new instance of SmellConfiguration.



16
17
18
# File 'lib/reek/smell_configuration.rb', line 16

def initialize(hash)
  @options = hash
end

Instance Attribute Details

#optionsObject (readonly, private)

Returns the value of attribute options.



44
45
46
# File 'lib/reek/smell_configuration.rb', line 44

def options
  @options
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/reek/smell_configuration.rb', line 24

def enabled?
  options[ENABLED_KEY]
end

#merge(new_options) ⇒ Object



20
21
22
# File 'lib/reek/smell_configuration.rb', line 20

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

#overrides_for(context) ⇒ Object



28
29
30
# File 'lib/reek/smell_configuration.rb', line 28

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

#value(key, context) ⇒ Object

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.



37
38
39
40
# File 'lib/reek/smell_configuration.rb', line 37

def value(key, context)
  overrides_for(context).each { |conf| return conf[key] if conf.key?(key) }
  options.fetch(key)
end