class Rulebow::Ignore
Deprecated: Encapsulates list of file globs to be ignored.
Public Class Methods
new(ignore)
click to toggle source
Initialize new instance of Ignore
.
Returns nothing.
# File lib/rulebow/ignore.rb, line 12 def initialize(ignore) @ignore = ignore.to_a end
Public Instance Methods
concat(*globs)
click to toggle source
# File lib/rulebow/ignore.rb, line 61 def concat(*globs) @ignore.concat(globs.flatten) end
each() { |g| ... }
click to toggle source
# File lib/rulebow/ignore.rb, line 41 def each to_a.each{ |g| yield g } end
filter(files)
click to toggle source
Filter a list of files in accordance with the ignore list.
files - The list of files. [Array<String>]
Returns [Array<String>]
# File lib/rulebow/ignore.rb, line 22 def filter(files) list = [] files.each do |file| hit = any? do |pattern| match?(pattern, file) end list << file unless hit end list end
fnmatch?(pattern, file, mode=File::FNM_PATHNAME)
click to toggle source
Shortcut to ‘File.fnmatch?` method.
Returns [Boolean]
# File lib/rulebow/ignore.rb, line 130 def fnmatch?(pattern, file, mode=File::FNM_PATHNAME) File.fnmatch?(pattern, file, File::FNM_PATHNAME) end
match?(pattern, file)
click to toggle source
Given a pattern and a file, does the file match the pattern? This code is based on the rules used by git’s .gitignore file.
TODO: The code is probably not quite right.
Returns [Boolean]
# File lib/rulebow/ignore.rb, line 105 def match?(pattern, file) if pattern.start_with?('!') return !match?(pattern.sub('!','').strip) end dir = pattern.end_with?('/') pattern = pattern.chomp('/') if dir if pattern.start_with?('/') fnmatch?(pattern.sub('/',''), file) else if dir fnmatch?(File.join(pattern, '**', '*'), file) || fnmatch?(pattern, file) && File.directory?(file) elsif pattern.include?('/') fnmatch?(pattern, file) else fnmatch?(File.join('**',pattern), file) end end end
replace(*globs)
click to toggle source
# File lib/rulebow/ignore.rb, line 56 def replace(*globs) @ignore = globs.flatten end
size()
click to toggle source
# File lib/rulebow/ignore.rb, line 46 def size to_a.size end
to_a()
click to toggle source
# File lib/rulebow/ignore.rb, line 51 def to_a @ignore #||= load_ignore end