class Guard::Git::ChangedFilesMatcher

Only matches files that both:

Public Class Methods

new(pattern) click to toggle source
# File lib/guard/git/changed_files_matcher.rb, line 10
def initialize(pattern)
  @pattern = pattern
end

Public Instance Methods

match(filename_or_pathname) click to toggle source
# File lib/guard/git/changed_files_matcher.rb, line 14
def match(filename_or_pathname)
  path = filename_or_pathname.to_s
  result = @pattern.match(path)
  return nil if result.nil? || skip_file?(path)

  result
end

Private Instance Methods

always_allowed?(path) click to toggle source
# File lib/guard/git/changed_files_matcher.rb, line 32
def always_allowed?(path)
  ignored_files.include?(path)
end
changed?(path) click to toggle source
# File lib/guard/git/changed_files_matcher.rb, line 28
def changed?(path)
  changed_files.include?(path)
end
changed_files() click to toggle source
# File lib/guard/git/changed_files_matcher.rb, line 40
def changed_files
  `git status --porcelain`.lines.map do |line|
    line.chomp.split(' ').last
  end
end
ignored_files() click to toggle source
# File lib/guard/git/changed_files_matcher.rb, line 36
def ignored_files
  `git ls-files --others -i --exclude-standard`.lines.map(&:chomp)
end
skip_file?(path) click to toggle source
# File lib/guard/git/changed_files_matcher.rb, line 24
def skip_file?(path)
  !changed?(path) && !always_allowed?(path)
end