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
- #extra_pattern ⇒ 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.
10 11 12 13 14 15 16 |
# File 'lib/pre-commit/checks/grep.rb', line 10 def initialize(*) super @extra_grep = nil @message = nil @pattern = nil end |
Instance Method Details
#call(staged_files) ⇒ Object
general code:
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pre-commit/checks/grep.rb', line 48 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? results = [ execute(args, success_status: false), extra_execute(files) ].compact results.empty? ? nil : results.join('') end.compact result.empty? ? nil : parse_errors(, result) end |
#extra_grep ⇒ Object
30 31 32 |
# File 'lib/pre-commit/checks/grep.rb', line 30 def extra_grep @extra_grep or [] end |
#extra_pattern ⇒ Object
42 43 44 |
# File 'lib/pre-commit/checks/grep.rb', line 42 def extra_pattern @extra_pattern end |
#files_filter(staged_files) ⇒ Object
overwrite those:
26 27 28 |
# File 'lib/pre-commit/checks/grep.rb', line 26 def files_filter(staged_files) staged_files end |
#message ⇒ Object
34 35 36 |
# File 'lib/pre-commit/checks/grep.rb', line 34 def @message or "" end |
#pattern ⇒ Object
38 39 40 |
# File 'lib/pre-commit/checks/grep.rb', line 38 def pattern @pattern or raise PaternNotSet.new end |