Class: Reek::Source::SourceLocator
- Inherits:
-
Object
- Object
- Reek::Source::SourceLocator
- Defined in:
- lib/reek/source/source_locator.rb
Overview
Finds Ruby source files in a filesystem.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
private
Returns the value of attribute configuration.
-
#options ⇒ Object
readonly
private
Returns the value of attribute options.
-
#paths ⇒ Object
readonly
private
Returns the value of attribute paths.
Instance Method Summary collapse
- #current_directory?(path) ⇒ Boolean private
- #hidden_directory?(path) ⇒ Boolean private
- #ignore_file?(path) ⇒ Boolean private
- #ignore_path?(path) ⇒ Boolean private
-
#initialize(paths, configuration: Configuration::AppConfiguration.default, options: Reek::CLI::Options.new) ⇒ SourceLocator
constructor
Initialize with the paths we want to search.
- #path_excluded?(path) ⇒ Boolean private
- #print_no_such_file_error(path) ⇒ Object private
- #ruby_file?(path) ⇒ Boolean private
- #source_files_from_path(given_path) ⇒ Object private
- #source_paths ⇒ Object private
-
#sources ⇒ Array<Pathname>
Traverses all paths we initialized the SourceLocator with, finds all relevant Ruby files and returns them as a list.
Constructor Details
#initialize(paths, configuration: Configuration::AppConfiguration.default, options: Reek::CLI::Options.new) ⇒ SourceLocator
Initialize with the paths we want to search.
paths - a list of paths as Strings
15 16 17 18 19 20 21 22 |
# File 'lib/reek/source/source_locator.rb', line 15 def initialize(paths, configuration: Configuration::AppConfiguration.default, options: Reek::CLI::Options.new) @options = @paths = paths.flat_map do |string| path = Pathname.new(string) current_directory?(path) ? path.entries : path end @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly, private)
Returns the value of attribute configuration.
34 35 36 |
# File 'lib/reek/source/source_locator.rb', line 34 def configuration @configuration end |
#options ⇒ Object (readonly, private)
Returns the value of attribute options.
34 35 36 |
# File 'lib/reek/source/source_locator.rb', line 34 def @options end |
#paths ⇒ Object (readonly, private)
Returns the value of attribute paths.
34 35 36 |
# File 'lib/reek/source/source_locator.rb', line 34 def paths @paths end |
Instance Method Details
#current_directory?(path) ⇒ Boolean (private)
94 95 96 |
# File 'lib/reek/source/source_locator.rb', line 94 def current_directory?(path) [Pathname.new('.'), Pathname.new('./')].include?(path) end |
#hidden_directory?(path) ⇒ Boolean (private)
80 81 82 |
# File 'lib/reek/source/source_locator.rb', line 80 def hidden_directory?(path) path.basename.to_s.start_with? '.' end |
#ignore_file?(path) ⇒ Boolean (private)
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/reek/source/source_locator.rb', line 58 def ignore_file?(path) if .force_exclusion? path.ascend do |ascendant| break true if path_excluded?(ascendant) false end else path_excluded?(path) end end |
#ignore_path?(path) ⇒ Boolean (private)
84 85 86 |
# File 'lib/reek/source/source_locator.rb', line 84 def ignore_path?(path) path_excluded?(path) || hidden_directory?(path) end |
#path_excluded?(path) ⇒ Boolean (private)
70 71 72 |
# File 'lib/reek/source/source_locator.rb', line 70 def path_excluded?(path) configuration.path_excluded?(path) end |
#print_no_such_file_error(path) ⇒ Object (private)
75 76 77 |
# File 'lib/reek/source/source_locator.rb', line 75 def print_no_such_file_error(path) warn "Error: No such file - #{path}" end |
#ruby_file?(path) ⇒ Boolean (private)
89 90 91 |
# File 'lib/reek/source/source_locator.rb', line 89 def ruby_file?(path) path.extname == '.rb' end |
#source_files_from_path(given_path) ⇒ Object (private)
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/reek/source/source_locator.rb', line 46 def source_files_from_path(given_path) relevant_paths = [] given_path.find do |path| if path.directory? Find.prune if ignore_path?(path) elsif ruby_file?(path) relevant_paths << path unless ignore_file?(path) end end relevant_paths end |
#source_paths ⇒ Object (private)
36 37 38 39 40 41 42 43 44 |
# File 'lib/reek/source/source_locator.rb', line 36 def source_paths paths.each_with_object([]) do |given_path, relevant_paths| if given_path.exist? relevant_paths.concat source_files_from_path(given_path) else print_no_such_file_error(given_path) end end end |
#sources ⇒ Array<Pathname>
Traverses all paths we initialized the SourceLocator with, finds all relevant Ruby files and returns them as a list.
28 29 30 |
# File 'lib/reek/source/source_locator.rb', line 28 def sources source_paths end |