Class: PreCommit::Checks::Grep

Inherits:
Plugin
  • Object
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:



32
33
34
35
36
37
38
# File 'lib/pre-commit/checks/grep.rb', line 32

def call(staged_files)
  staged_files = files_filter(staged_files)
  return if staged_files.empty?
  errors = `#{grep} #{pattern} #{staged_files.join(" ")}#{extra_grep}`
  return unless $?.success?
  "#{message}#{errors}"
end

#extra_grepObject



18
19
20
# File 'lib/pre-commit/checks/grep.rb', line 18

def extra_grep
  @extra_grep or ""
end

#files_filter(staged_files) ⇒ Object

overwrite those:



14
15
16
# File 'lib/pre-commit/checks/grep.rb', line 14

def files_filter(staged_files)
  staged_files
end

#messageObject



22
23
24
# File 'lib/pre-commit/checks/grep.rb', line 22

def message
  @message or ""
end

#patternObject



26
27
28
# File 'lib/pre-commit/checks/grep.rb', line 26

def pattern
  @pattern or raise PaternNotSet.new
end