module Roger::Helpers::GetFiles
Helper to include the get_files
method
Constants
- GLOB_OPTIONS
Public Instance Methods
get_files(globs, excludes = [])
click to toggle source
Get files from a path, skipping excludes.
@param [Array] globs an array of file path globs that will be globbed
against the project path
@param [Array] excludes an array of regexps that will be excluded
from the result.
# 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 = [])
click to toggle source
See if a file matches globs/excludes
@param [.to_s] path the path to match @param [Array] globs an array of file path globs that will be matched against path @param [Array] exclude an array of regexps that will be matched negatively against path
@return [Boolean] Did the passed path match against the globs and excludes?
# 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
Protected Instance Methods
get_files_default_path()
click to toggle source
The default path to use when calling get_files
# File lib/roger/helpers/get_files.rb, line 38 def get_files_default_path raise "Implement #get_files_default_path in your class" end