Method: Polytrix::Util::FileSystem#find_file
- Defined in:
- lib/polytrix/util.rb
#find_file(search_path, scenario_name, ignored_patterns = nil) ⇒ Object
Finds a file by loosely matching the file name to a scenario name
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/polytrix/util.rb', line 199 def find_file(search_path, scenario_name, ignored_patterns = nil) ignored_patterns ||= read_gitignore(search_path) glob_string = "#{search_path}/**/*#{slugify(scenario_name)}.*" potential_files = Dir.glob(glob_string, File::FNM_CASEFOLD) potential_files.concat Dir.glob(glob_string.gsub('_', '-'), File::FNM_CASEFOLD) potential_files.concat Dir.glob(glob_string.gsub('_', ''), File::FNM_CASEFOLD) # Filter out ignored filesFind the first file, not including generated files files = potential_files.select do |f| !ignored? ignored_patterns, search_path, f end # Select the shortest path, likely the best match file = files.min_by(&:length) fail Errno::ENOENT, "No file was found for #{scenario_name} within #{search_path}" if file.nil? Pathname.new file end |