Class: Reek::Configuration::AppConfiguration

Inherits:
Object
  • Object
show all
Includes:
ConfigurationValidator
Defined in:
lib/reek/configuration/app_configuration.rb

Overview

Reek’s application configuration.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_directiveObject (private)



98
99
100
# File 'lib/reek/configuration/app_configuration.rb', line 98

def default_directive
  @default_directive ||= {}.extend(DefaultDirective)
end

#directory_directivesObject (private)



94
95
96
# File 'lib/reek/configuration/app_configuration.rb', line 94

def directory_directives
  @directory_directives ||= {}.extend(DirectoryDirectives)
end

#excluded_pathsObject (private)



102
103
104
# File 'lib/reek/configuration/app_configuration.rb', line 102

def excluded_paths
  @excluded_paths ||= [].extend(ExcludedPaths)
end

Class Method Details

.defaultObject



54
55
56
# File 'lib/reek/configuration/app_configuration.rb', line 54

def self.default
  new(values: {})
end

.from_default_pathAppConfiguration

Instantiate a configuration via the default path.

Returns:



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.

Parameters:

  • hash (Hash)

    The configuration hash to load.

Returns:



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.

Parameters:

  • path (Pathname)

    the path to the config file.

Returns:



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.

Parameters:

  • source_via (String)

    the source of the code inspected

Returns:

  • (Hash)

    the directory directive for the source with the default directive reverse-merged into it.



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

Returns:

  • (Boolean)


69
70
71
# File 'lib/reek/configuration/app_configuration.rb', line 69

def path_excluded?(path)
  excluded_paths.map(&:expand_path).include?(path.expand_path)
end