Class: PreCommit::Checks::Grep

Inherits:
Shell show all
Defined in:
lib/pre-commit/checks/grep.rb

Defined Under Namespace

Classes: PaternNotSet

Instance Attribute Summary

Attributes inherited from Plugin

#config, #pluginator

Instance Method Summary collapse

Methods inherited from Plugin

#initialize, #name

Constructor Details

This class inherits a constructor from PreCommit::Checks::Plugin

Instance Method Details

#call(staged_files) ⇒ Object

general code:



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pre-commit/checks/grep.rb', line 34

def call(staged_files)
  staged_files = files_filter(staged_files)
  return if staged_files.empty?

  result =
  in_groups(staged_files).map do |files|
    args = grep + [pattern] + files
    args += ["|", "grep"] + extra_grep if !extra_grep.nil? and !extra_grep.empty?
    execute(args, success_status: false)
  end.compact

  result.empty? ? nil : parse_errors(message, result)
end

#extra_grepObject



20
21
22
# File 'lib/pre-commit/checks/grep.rb', line 20

def extra_grep
  @extra_grep or []
end

#files_filter(staged_files) ⇒ Object

overwrite those:



16
17
18
# File 'lib/pre-commit/checks/grep.rb', line 16

def files_filter(staged_files)
  staged_files
end

#messageObject



24
25
26
# File 'lib/pre-commit/checks/grep.rb', line 24

def message
  @message or ""
end

#patternObject



28
29
30
# File 'lib/pre-commit/checks/grep.rb', line 28

def pattern
  @pattern or raise PaternNotSet.new
end