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

Instance Method Details

#get_files(globs, excludes = []) ⇒ Object

Get files from a path, skipping excludes.

Parameters:

  • globs (Array)

    an array of file path globs that will be globbed against the project path

  • excludes (Array) (defaults to: [])

    an array of regexps that will be excluded from the result.



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

Parameters:

  • path (.to_s)

    the path to match

  • globs (Array)

    an array of file path globs that will be matched against path

  • exclude (Array)

    an array of regexps that will be matched negatively against path

Returns:

  • (Boolean)

    Did the passed path match against the globs and 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