Class: PreCommit::Checks::Grep
- Defined in:
- lib/pre-commit/checks/grep.rb
Direct Known Subclasses
BeforeAll, ConsoleLog, Debugger, GemfilePath, MergeConflict, Pry, RspecFocus, RubySymbolHashrockets, Tabs
Defined Under Namespace
Classes: PaternNotSet
Instance Attribute Summary
Attributes inherited from Plugin
Instance Method Summary collapse
-
#call(staged_files) ⇒ Object
general code:.
- #extra_grep ⇒ Object
-
#files_filter(staged_files) ⇒ Object
overwrite those:.
-
#initialize ⇒ Grep
constructor
A new instance of Grep.
- #message ⇒ Object
- #pattern ⇒ Object
Methods inherited from Plugin
Constructor Details
#initialize ⇒ Grep
Returns a new instance of Grep.
8 9 10 11 12 13 14 |
# File 'lib/pre-commit/checks/grep.rb', line 8 def initialize(*) super @extra_grep = nil = nil @pattern = nil end |
Instance Method Details
#call(staged_files) ⇒ Object
general code:
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pre-commit/checks/grep.rb', line 42 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(, result) end |
#extra_grep ⇒ Object
28 29 30 |
# File 'lib/pre-commit/checks/grep.rb', line 28 def extra_grep @extra_grep or [] end |
#files_filter(staged_files) ⇒ Object
overwrite those:
24 25 26 |
# File 'lib/pre-commit/checks/grep.rb', line 24 def files_filter(staged_files) staged_files end |
#message ⇒ Object
32 33 34 |
# File 'lib/pre-commit/checks/grep.rb', line 32 def or "" end |
#pattern ⇒ Object
36 37 38 |
# File 'lib/pre-commit/checks/grep.rb', line 36 def pattern @pattern or raise PaternNotSet.new end |