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:



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

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

#extra_grepObject



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

def extra_grep
  @extra_grep or ""
end

#files_filter(staged_files) ⇒ Object

overwrite those:



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

def files_filter(staged_files)
  staged_files
end

#messageObject



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

def message
  @message or ""
end

#patternObject



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

def pattern
  @pattern or raise PaternNotSet.new
end