Class: Reek::SmellConfiguration
- Inherits:
-
Object
- Object
- Reek::SmellConfiguration
- 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
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
-
#options ⇒ Object
readonly
private
Returns the value of attribute options.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(hash) ⇒ SmellConfiguration
constructor
A new instance of SmellConfiguration.
- #merge(new_options) ⇒ Object
- #overrides_for(context) ⇒ Object
-
#value(key, context) ⇒ Object
Retrieves the value, if any, for the given
key
in the givencontext
.
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
#options ⇒ Object (readonly, private)
Returns the value of attribute options.
44 45 46 |
# File 'lib/reek/smell_configuration.rb', line 44 def @options end |
Instance Method Details
#enabled? ⇒ Boolean
24 25 26 |
# File 'lib/reek/smell_configuration.rb', line 24 def enabled? [ENABLED_KEY] end |
#merge(new_options) ⇒ Object
20 21 22 |
# File 'lib/reek/smell_configuration.rb', line 20 def merge() .merge!() end |
#overrides_for(context) ⇒ Object
28 29 30 |
# File 'lib/reek/smell_configuration.rb', line 28 def overrides_for(context) Overrides.new(.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) } .fetch(key) end |