Class: TestLauncher::Search::Ag::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/test_launcher/search/ag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell) ⇒ Interface

Returns a new instance of Interface.



11
12
13
# File 'lib/test_launcher/search/ag.rb', line 11

def initialize(shell)
  @shell = shell
end

Instance Attribute Details

#shellObject (readonly)

Returns the value of attribute shell.



9
10
11
# File 'lib/test_launcher/search/ag.rb', line 9

def shell
  @shell
end

Instance Method Details

#grep(regex, file_pattern) ⇒ Object



19
20
21
# File 'lib/test_launcher/search/ag.rb', line 19

def grep(regex, file_pattern)
  shell.run("ag #{Shellwords.escape(regex)} --file-search-regex '#{pattern_to_regex(file_pattern)}'")
end

#ls_files(pattern) ⇒ Object



15
16
17
# File 'lib/test_launcher/search/ag.rb', line 15

def ls_files(pattern)
  shell.run("ag -g '.*#{pattern_to_regex(pattern)}.*'")
end

#pattern_to_regex(pattern) ⇒ Object



27
28
29
# File 'lib/test_launcher/search/ag.rb', line 27

def pattern_to_regex(pattern)
  pattern.gsub("*", ".*")
end

#root_pathObject



23
24
25
# File 'lib/test_launcher/search/ag.rb', line 23

def root_path
  @result ||= (ENV['TEST_LAUNCHER__DIR'] || Dir.pwd)
end