Class: Reek::SmellConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/reek/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.



18
19
20
# File 'lib/reek/configuration.rb', line 18

def initialize(hash)
  @hash = hash
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



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

def hash
  @hash
end

Instance Method Details

#enabled?Boolean

SMELL: Getter

Returns:

  • (Boolean)


23
24
25
# File 'lib/reek/configuration.rb', line 23

def enabled?
  @hash[ENABLED_KEY]
end

#overrides_for(context) ⇒ Object



27
28
29
# File 'lib/reek/configuration.rb', line 27

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

#value(key, context, fall_back) ⇒ Object

Retrieves the value, if any, for the given key.

Returns fall_back if this config has no value for the key.



35
36
37
38
# File 'lib/reek/configuration.rb', line 35

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