Sha256: c1c7360929cd8a2f81911d96f01fceb97d1f1ee80ea5d9bbf49defcf547fb3a1
Contents?: true
Size: 1.11 KB
Versions: 10
Compression:
Stored size: 1.11 KB
Contents
require 'pre-commit/checks/plugin' module PreCommit module Checks class Grep < Plugin class PaternNotSet < StandardError def message "Please define 'pattern' method." end end # overwrite those: def files_filter(staged_files) staged_files end def extra_grep @extra_grep or "" end def message @message or "" end def pattern @pattern or raise PaternNotSet.new end # general code: 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 private def grep(grep_version = nil) grep_version ||= detect_grep_version if grep_version =~ /FreeBSD/ "grep -EnIH" else "grep -PnIH" end end def detect_grep_version `grep --version | head -n 1 | sed -e 's/^[^0-9.]*\([0-9.]*\)$/\1/'` end end end end
Version data entries
10 entries across 10 versions & 1 rubygems