Class: Reek::SmellConfiguration
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
orfalse
. '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
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
SMELL: Getter.
-
#initialize(hash) ⇒ SmellConfiguration
constructor
A new instance of SmellConfiguration.
- #overrides_for(context) ⇒ Object
-
#value(key, context, fall_back) ⇒ Object
Retrieves the value, if any, for the given
key
.
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
#hash ⇒ Object (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
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 |