Module: Ag

Extended by:
Ag
Included in:
Ag
Defined in:
lib/the_ruby_searcher.rb

Instance Method Summary collapse

Instance Method Details

#search(pattern, path, e = "ag") ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/the_ruby_searcher.rb', line 4

def search(pattern, path, e = "ag")
  engine = find_engine(e)
  warn(e,engine) if e != engine
  cmd = [engine, pattern, path, "-n"]
  out = IO.popen(cmd).read
  if out != ""
    out.split("\n").map{ |l| l.split(":") }.to_h
  else
    raise SystemCallError, "Something went wrong, check the logs."
  end
end