class TestLauncher::Search::Ag

Constants

NotInRepoError

Attributes

interface[R]

Public Class Methods

new(shell, interface=Interface.new(shell)) click to toggle source
# File lib/test_launcher/search/ag.rb, line 37
def initialize(shell, interface=Interface.new(shell))
  @interface = interface
  Dir.chdir(root_path) # MOVE ME!
end

Public Instance Methods

find_files(pattern) click to toggle source
# File lib/test_launcher/search/ag.rb, line 42
def find_files(pattern)
  relative_pattern = strip_system_path(pattern)
  interface.ls_files(relative_pattern).map {|f| system_path(f)}
end
grep(regex, file_pattern: '*') click to toggle source
# File lib/test_launcher/search/ag.rb, line 47
def grep(regex, file_pattern: '*')
  results = interface.grep(regex, strip_system_path(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_launcher/search/ag.rb, line 57
def interpret_grep_result(grep_result)
  splits = grep_result.split(/:/)
  file = splits.shift.strip
  line_number = splits.shift.strip.to_i
  # we rejoin on ':' because our
  # code may have colons inside of it.
  #
  # example:
  # path/to/file:126: run_method(a: A, b: B)
  #
  # so shift the first one out, then
  # rejoin the rest
  line = splits.join(':').strip

  # TODO: Oh goodness, why is this not a class
  {
    :file => system_path(file),
    :line_number => line_number.to_i,
    :line => line,
  }
end
root_path() click to toggle source
# File lib/test_launcher/search/ag.rb, line 87
def root_path
  @root_path ||= interface.root_path
end
shell() click to toggle source
# File lib/test_launcher/search/ag.rb, line 91
def shell
  @shell
end
strip_system_path(file) click to toggle source
# File lib/test_launcher/search/ag.rb, line 83
def strip_system_path(file)
  file.sub(/^#{root_path}\//, '')
end
system_path(file) click to toggle source
# File lib/test_launcher/search/ag.rb, line 79
def system_path(file)
  File.join(root_path, file)
end