class GitHooks::PreCommit::PreventDebugger

Attributes

git_repository[R]

Public Class Methods

new(git_repository) click to toggle source
# File lib/git_hooks/pre_commit/prevent_debugger.rb, line 10
def initialize(git_repository)
  @git_repository = git_repository
end
validate(*) click to toggle source
# File lib/git_hooks/pre_commit/prevent_debugger.rb, line 6
def self.validate(*)
  new(GitHooks.configurations.git_repository).validate
end

Public Instance Methods

validate() click to toggle source
# File lib/git_hooks/pre_commit/prevent_debugger.rb, line 14
def validate
  abort(
    "Prevented commit with debugger in #{files_with_debugger}"
  ) if files_with_debugger.any?
end

Private Instance Methods

contains_debugger?() click to toggle source
# File lib/git_hooks/pre_commit/prevent_debugger.rb, line 33
def contains_debugger?
  -> (file) { File.read(file) =~ debugger_regex }
end
debugger_regex() click to toggle source
# File lib/git_hooks/pre_commit/prevent_debugger.rb, line 37
def debugger_regex
  Regexp.union(
    %w(binding.pry binding.remote_pry save_and_open_page debugger)
  )
end
files_with_debugger() click to toggle source
# File lib/git_hooks/pre_commit/prevent_debugger.rb, line 22
def files_with_debugger
  git_repository
    .added_or_modified
    .select(&ruby_files)
    .select(&contains_debugger?)
end
ruby_files() click to toggle source
# File lib/git_hooks/pre_commit/prevent_debugger.rb, line 29
def ruby_files
  -> (file) { File.extname(file) == '.rb' }
end