class TestRun::Searchers::GitSearcher

Public Instance Methods

find_files(pattern) click to toggle source
# File lib/test_run/searchers/git_searcher.rb, line 5
def find_files(pattern)
  shell.run("git ls-files '*#{pattern}*'")
end
grep(regex, file_pattern: '*') click to toggle source
# File lib/test_run/searchers/git_searcher.rb, line 9
def grep(regex, file_pattern: '*')
  results = shell.run("git grep --untracked '#{regex}' -- '#{file_pattern}'")
  results.map do |result|
    interpret_grep_result(result)
  end
end

Private Instance Methods

interpret_grep_result(grep_result) click to toggle source
# File lib/test_run/searchers/git_searcher.rb, line 18
def interpret_grep_result(grep_result)
  splits = grep_result.split(/:/)
  file = splits.shift.strip
  # we rejoin on ':' because our
  # code may have colons inside of it.
  #
  # example:
  # path/to/file: run_method(a: A, b: B)
  #
  # so shift the first one out, then
  # rejoin the rest
  line = splits.join(':').strip

  {
    :file => file,
    :line => line,
  }
end