Class: TestLauncher::Search::Git

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

Defined Under Namespace

Classes: Interface

Constant Summary collapse

NotInRepoError =
Class.new(BaseError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell, interface = Interface.new(shell)) ⇒ Git

Returns a new instance of Git.



43
44
45
46
# File 'lib/test_launcher/search/git.rb', line 43

def initialize(shell, interface=Interface.new(shell))
  @interface = interface
  Dir.chdir(root_path) # MOVE ME!
end

Instance Attribute Details

#interfaceObject (readonly)

Returns the value of attribute interface.



41
42
43
# File 'lib/test_launcher/search/git.rb', line 41

def interface
  @interface
end

Instance Method Details

#find_files(pattern) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/test_launcher/search/git.rb', line 48

def find_files(pattern)
  relative_pattern = strip_system_path(pattern)

  if File.exist?(relative_pattern)
    [system_path(relative_pattern)]
  else
    interface.ls_files(relative_pattern).map {|f| system_path(f)}
  end
end

#grep(regex, file_pattern: '*') ⇒ Object



58
59
60
61
62
63
# File 'lib/test_launcher/search/git.rb', line 58

def grep(regex, file_pattern: '*')
  results = interface.grep(regex, file_pattern)
  results.map do |result|
    interpret_grep_result(result)
  end
end