Class: Reek::Configuration::AppConfiguration
- Inherits:
-
Object
- Object
- Reek::Configuration::AppConfiguration
- Includes:
- ConfigurationValidator
- Defined in:
- lib/reek/configuration/app_configuration.rb
Overview
Reek’s application configuration.
Instance Attribute Summary collapse
- #default_directive ⇒ Object private
- #directory_directives ⇒ Object private
- #excluded_paths ⇒ Object private
Class Method Summary collapse
- .default ⇒ Object
-
.from_default_path ⇒ AppConfiguration
Instantiate a configuration via the default path.
-
.from_hash(hash) ⇒ AppConfiguration
Instantiate a configuration by passing everything in.
-
.from_path(path) ⇒ AppConfiguration
Instantiate a configuration via the given path.
Instance Method Summary collapse
-
#directive_for(source_via) ⇒ Hash
Returns the directive for a given directory.
-
#initialize(values: {}) ⇒ AppConfiguration
constructor
A new instance of AppConfiguration.
- #load_values(values) ⇒ Object
- #path_excluded?(path) ⇒ Boolean
Methods included from ConfigurationValidator
#key_to_smell_detector, #smell_type?, #with_valid_directory
Constructor Details
#initialize(values: {}) ⇒ AppConfiguration
Returns a new instance of AppConfiguration.
86 87 88 |
# File 'lib/reek/configuration/app_configuration.rb', line 86 def initialize(values: {}) load_values(values) end |
Instance Attribute Details
#default_directive ⇒ Object (private)
98 99 100 |
# File 'lib/reek/configuration/app_configuration.rb', line 98 def default_directive @default_directive ||= {}.extend(DefaultDirective) end |
#directory_directives ⇒ Object (private)
94 95 96 |
# File 'lib/reek/configuration/app_configuration.rb', line 94 def directory_directives @directory_directives ||= {}.extend(DirectoryDirectives) end |
#excluded_paths ⇒ Object (private)
102 103 104 |
# File 'lib/reek/configuration/app_configuration.rb', line 102 def excluded_paths @excluded_paths ||= [].extend(ExcludedPaths) end |
Class Method Details
.default ⇒ Object
54 55 56 |
# File 'lib/reek/configuration/app_configuration.rb', line 54 def self.default new(values: {}) end |
.from_default_path ⇒ AppConfiguration
Instantiate a configuration via the default path.
36 37 38 39 |
# File 'lib/reek/configuration/app_configuration.rb', line 36 def self.from_default_path values = ConfigurationFileFinder.find_and_load(path: nil) new(values: values) end |
.from_hash(hash) ⇒ AppConfiguration
Instantiate a configuration by passing everything in.
Loads the configuration from a hash of the form that is loaded from a .reek
config file.
50 51 52 |
# File 'lib/reek/configuration/app_configuration.rb', line 50 def self.from_hash(hash) new(values: hash) end |
.from_path(path) ⇒ AppConfiguration
Instantiate a configuration via the given path.
26 27 28 29 |
# File 'lib/reek/configuration/app_configuration.rb', line 26 def self.from_path(path) values = ConfigurationFileFinder.find_and_load(path: path) new(values: values) end |
Instance Method Details
#directive_for(source_via) ⇒ Hash
Returns the directive for a given directory.
64 65 66 67 |
# File 'lib/reek/configuration/app_configuration.rb', line 64 def directive_for(source_via) hit = directory_directives.directive_for(source_via) hit ? default_directive.merge(hit) : default_directive end |
#load_values(values) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/reek/configuration/app_configuration.rb', line 73 def load_values(values) values.each do |key, value| case key when EXCLUDE_PATHS_KEY excluded_paths.add value when DIRECTORIES_KEY directory_directives.add value when DETECTORS_KEY default_directive.add value end end end |
#path_excluded?(path) ⇒ Boolean
69 70 71 |
# File 'lib/reek/configuration/app_configuration.rb', line 69 def path_excluded?(path) excluded_paths.map(&:expand_path).include?(path.) end |