Module: Roger::Helpers::GetFiles
- Included in:
- Rack::Roger, Release, Test
- Defined in:
- lib/roger/helpers/get_files.rb
Overview
Helper to include the get_files method
Constant Summary collapse
- GLOB_OPTIONS =
File::FNM_PATHNAME | File::FNM_EXTGLOB | File::FNM_DOTMATCH
Instance Method Summary collapse
-
#get_files(globs, excludes = []) ⇒ Object
Get files from a path, skipping excludes.
-
#match_path(path, globs, excludes = []) ⇒ Boolean
See if a file matches globs/excludes.
Instance Method Details
#get_files(globs, excludes = []) ⇒ Object
Get files from a path, skipping excludes.
13 14 15 16 17 18 |
# File 'lib/roger/helpers/get_files.rb', line 13 def get_files(globs, excludes = []) path = Pathname.new(get_files_default_path) files = globs.map { |g| Dir.glob(path + g, GLOB_OPTIONS) }.flatten files.reject! { |file| excludes.detect { |e| file.match(e) } } if excludes.any? files.select { |file| File.file?(file) } end |
#match_path(path, globs, excludes = []) ⇒ Boolean
See if a file matches globs/excludes
27 28 29 30 31 32 33 |
# File 'lib/roger/helpers/get_files.rb', line 27 def match_path(path, globs, excludes = []) path = path.to_s match = globs.detect { |glob| File.fnmatch?(glob, path, GLOB_OPTIONS) } return false unless match # No need to check excludes if we don't match anyway !excludes.find { |e| path.match(e) } end |