Module: PoolParty::SearchablePaths::InstanceMethods
- Defined in:
- lib/poolparty/modules/searchable_paths.rb
Instance Method Summary collapse
-
#search_in_known_locations(filepath, additional_search_paths = []) ⇒ Object
(also: #find_file)
Searches for
filepath
in thesearchable_paths
ifffilepath
doesn’t exist.
Instance Method Details
#search_in_known_locations(filepath, additional_search_paths = []) ⇒ Object Also known as: find_file
Searches for filepath
in the searchable_paths
iff filepath
doesn’t exist. e.g. filepath
is interpreted first as an absolute path, if filepath
doesn’t exist verbatim then it looks for the file in the searchable_paths.
Returns nil
if the file cannot be found.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/poolparty/modules/searchable_paths.rb', line 81 def search_in_known_locations(filepath, additional_search_paths=[]) return filepath if ::File.exists?(filepath) # return the file if its an absolute path additional_search_paths.each do |path| full_path = ::File.(path / filepath) return full_path if ::File.exists?(full_path) end self.class.searchable_paths.each do |path| self.class.searchable_paths_dirs.each do |dir| full_path = ::File.(path / dir / filepath) return full_path if ::File.exists?(full_path) end end nil end |