Sha256: ffbd97db062f04cf69d7aa42cc72c2ea17497ba0ebbb97870957c1bdca97a82c
Contents?: true
Size: 937 Bytes
Versions: 1
Compression:
Stored size: 937 Bytes
Contents
## # Ignore things ## class IgnoreFile attr_reader :statements COMMENT_OR_WHITESPACE = /^\s*(?:#.*)?$/.freeze def initialize(*args) @statements = [] args.each do |arg| case when arg.is_a?(Array) then push(arg) when File.exist?(arg) then load_file(arg) else push(arg) end end end def push(*arg) statements.push(*arg.flatten.map(&:strip)) statements.sort! statements.uniq! end alias_method :<<, :push def load_file(ifile) push(File.readlines(ifile).map(&:strip).reject do |line| line.empty? || line =~ COMMENT_OR_WHITESPACE end) end def ignored?(file) statements.any? { |statement| File.fnmatch?(statement, file) } end def apply(*files) files.flatten.reject do |file| file.strip.empty? || ignored?(file) end end def apply!(files) files.reject! do |file| file.strip.empty? || ignored?(file) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ignorefile-1.0.0 | lib/ignorefile.rb |