Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pre-commit hooks for Rails projects
#!/usr/bin/env ruby
# Pre-commit hooks to check the code for errant syntax issues, like logging messages, etc.
# Chris Cummer
# Check to see if I've left any debugging lines in the ruby files
def check_for_ruby_debug( flag )
run_cmd( flag, "grep -rls 'puts \">>' ../../app/**/*.rb", "Debug puts found in:" )
end
# Check to see if I've left any :focus rspec directives
def check_for_rspec_focus( flag )
run_cmd( flag, "grep -rls ', :focus' ../../spec/**/*.rb", "Rspec :focus directive found in:" )
end
def run_cmd( flag, cmd, msg )
result = `#{cmd}`
if '' != result
print_result( msg, result )
flag = true
end
flag
end
def print_result( msg, result )
puts "#{msg} \n"
puts result
puts "\n"
end
# ------------------------------ Main ------------------------------ #
flag = false
flag = check_for_ruby_debug( flag )
flag = check_for_rspec_focus( flag )
exit 1 if flag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.