Module: SearchablePaths::InstanceMethods

Defined in:
lib/mixins/searchable_paths.rb

Instance Method Summary collapse

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.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mixins/searchable_paths.rb', line 68

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.expand_path(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|
      next if path.nil?
      full_path = File.expand_path(path / dir / filepath)
      return full_path if File.exists?(full_path)
    end
  end
  nil
end