Module: File::Grep

Defined in:
lib/vex/base/filesystem/grep.rb

Defined Under Namespace

Modules: Etest

Instance Method Summary collapse

Instance Method Details

#grep(rex, *files) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/vex/base/filesystem/grep.rb', line 2

def grep(rex, *files)
  files = files.flatten
  
  unless block_given?
    results = []
    grep(rex, files) do |line, file, *args|
      results << [ line, file ]
    end
    return results
  end
  
  files.each do |file|
    File.readlines(file).each do |line|
      next unless matches = (rex.match(line))
      yield line, file, matches 
    end
  end
end