Module: FlossFunding::FileFinder Private
- Included in:
- ConfigFinder, ConfigLoader, Inclusion, Library
- Defined in:
- lib/floss_funding/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.
Common methods for finding files.
Class Method Summary collapse
-
.root_level=(level) ⇒ void
private
Set the artificial root level used to stop upward traversal when searching.
-
.root_level?(path, stop_dir) ⇒ Boolean
private
Check whether the given path has reached the configured root level or stop_dir.
Instance Method Summary collapse
-
#find_file_upwards(filename, start_dir, stop_dir = nil) ⇒ String?
private
Find the first occurrence of a file walking upward from a starting directory.
-
#find_last_file_upwards(filename, start_dir, stop_dir = nil) ⇒ String?
private
Find the last occurrence of a file while walking upward from a starting directory.
Class Method Details
.root_level=(level) ⇒ void
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.
This method returns an undefined value.
Set the artificial root level used to stop upward traversal when searching.
18 19 20 |
# File 'lib/floss_funding/file_finder.rb', line 18 def self.root_level=(level) @root_level = level end |
.root_level?(path, stop_dir) ⇒ Boolean
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.
Check whether the given path has reached the configured root level or stop_dir.
27 28 29 |
# File 'lib/floss_funding/file_finder.rb', line 27 def self.root_level?(path, stop_dir) (@root_level || stop_dir) == path.to_s end |
Instance Method Details
#find_file_upwards(filename, start_dir, stop_dir = nil) ⇒ String?
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.
Find the first occurrence of a file walking upward from a starting directory.
37 38 39 40 41 42 |
# File 'lib/floss_funding/file_finder.rb', line 37 def find_file_upwards(filename, start_dir, stop_dir = nil) traverse_files_upwards(filename, start_dir, stop_dir) do |file| # minimize iteration for performance return file if file end end |
#find_last_file_upwards(filename, start_dir, stop_dir = nil) ⇒ String?
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.
Find the last occurrence of a file while walking upward from a starting directory.
Useful for selecting the nearest ancestor config file when multiple are present.
51 52 53 54 55 |
# File 'lib/floss_funding/file_finder.rb', line 51 def find_last_file_upwards(filename, start_dir, stop_dir = nil) last_file = nil traverse_files_upwards(filename, start_dir, stop_dir) { |file| last_file = file } last_file end |