Module: TestBench::Bootstrap::Path
- Defined in:
- lib/test_bench/bootstrap.rb
Class Method Summary collapse
- .match?(pattern, string) ⇒ Boolean
- .search(path, include_pattern = nil, exclude_pattern = nil) ⇒ Object
- .search_directory(dir, files, include_pattern = nil, exclude_pattern = nil) ⇒ Object
Class Method Details
.match?(pattern, string) ⇒ Boolean
35 36 37 |
# File 'lib/test_bench/bootstrap.rb', line 35 def self.match?(pattern, string) ::File.fnmatch?(pattern, string) end |
.search(path, include_pattern = nil, exclude_pattern = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/test_bench/bootstrap.rb', line 39 def self.search(path, include_pattern=nil, exclude_pattern=nil) files = [] if ::File.directory?(path) search_directory(path, files, include_pattern, exclude_pattern) elsif ::File.exist?(path) files << path else raise LoadError, "no such file or directory -- #{path}" end files end |
.search_directory(dir, files, include_pattern = nil, exclude_pattern = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/test_bench/bootstrap.rb', line 53 def self.search_directory(dir, files, include_pattern=nil, exclude_pattern=nil) include_pattern ||= '*.rb' ::Dir[::File.join(dir, '**', '*')].each do |path| next if ::File.directory?(path) if match?(include_pattern, path) if exclude_pattern.nil? || !match?(exclude_pattern, path) files << path end end end end |