Module: Reek::Configuration::ConfigurationFileFinder Private

Defined in:
lib/reek/configuration/configuration_file_finder.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.

ConfigurationFileFinder is responsible for finding reek’s configuration.

There are 3 ways of passing ‘reek` a configuration file:

  1. Using the cli “-c” switch

  2. Having a file ending with .reek either in your current working directory or in a parent directory

  3. Having a file ending with .reek in your HOME directory

The order in which ConfigurationFileFinder tries to find such a configuration file is exactly like above.

Class Method Summary collapse

Class Method Details

.find(params = {}) ⇒ 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.

FIXME: switch to kwargs on upgrade to Ruby 2 and drop ‘params.fetch` calls: def find(options: nil, current: Pathname.pwd, home: Pathname.new(Dir.home))



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

def find(params = {})
  options = params.fetch(:options) { nil                    }
  current = params.fetch(:current) { Pathname.pwd           }
  home    = params.fetch(:home)    { Pathname.new(Dir.home) }
  find_by_cli(options) || find_by_dir(current) || find_by_dir(home)
end

.find_by_cli(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.



29
30
31
# File 'lib/reek/configuration/configuration_file_finder.rb', line 29

def find_by_cli(options)
  options && options.config_file
end

.find_by_dir(start) ⇒ 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.



33
34
35
36
37
38
39
# File 'lib/reek/configuration/configuration_file_finder.rb', line 33

def find_by_dir(start)
  start.ascend do |dir|
    files = dir.children.select(&:file?).sort
    found = files.find { |file| file.to_s.end_with?('.reek') }
    return found if found
  end
end