Module: Reek::Configuration::AppConfiguration Private

Defined in:
lib/reek/configuration/app_configuration.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Reek’s singleton configuration instance.

Constant Summary collapse

NON_SMELL_TYPE_KEYS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w(exclude_paths)
EXCLUDE_PATHS_KEY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'exclude_paths'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def configuration
  @configuration
end

Class Method Details

.configure_smell_repository(smell_repository) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
34
35
36
# File 'lib/reek/configuration/app_configuration.rb', line 28

def configure_smell_repository(smell_repository)
  # Let users call this method directly without having initialized AppConfiguration before
  # and if they do, initialize it without application context
  initialize_with(nil) unless @has_been_initialized
  for_smell_types.each do |klass_name, config|
    klass = load_smell_type(klass_name)
    smell_repository.configure(klass, config) if klass
  end
end

.exclude_pathsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
61
# File 'lib/reek/configuration/app_configuration.rb', line 57

def exclude_paths
  @exclude_paths ||= @configuration.
                     fetch(EXCLUDE_PATHS_KEY, []).
                     map { |path| path.chomp('/') }
end

.initialize_with(options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
# File 'lib/reek/configuration/app_configuration.rb', line 21

def initialize_with(options)
  @has_been_initialized = true
  configuration_file_path = ConfigurationFileFinder.find(options: options)
  return unless configuration_file_path
  load_from_file configuration_file_path
end

.load_from_file(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/reek/configuration/app_configuration.rb', line 38

def load_from_file(path)
  if File.size(path) == 0
    report_problem('Empty file', path)
    return
  end

  begin
    @configuration = YAML.load_file(path) || {}
  rescue => error
    raise_error(error.to_s, path)
  end

  raise_error('Not a hash', path) unless @configuration.is_a? Hash
end

.resetObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def reset
  @configuration.clear
end