Created
May 9, 2012 20:35
-
-
Save dougc84/2648611 to your computer and use it in GitHub Desktop.
AwesomePrint initializer aliasing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following snippet handles any calls to ap or awesome_print hanging out in your code, | |
# which can be particularly troublesome in a production environment where awesome_print isn't | |
# included in your Gemfile. | |
# If you have any inline "ap" or "awesome_print" calls, they will be aliased to | |
# puts (not using the alias method, that wasn't optimal). The output will also be logged at | |
# info level (feel free to change this depending on your needs) with the calling file and | |
# line number so you can find the offending calls. | |
# You can grep through your log files for "[ AP called from " to find any calls to ap. | |
# Throw this code in an initializer (awesome_print.rb) and modify as you wish. | |
# I only wrote code for ap and awesome_print - I don't really use ai or awesome_inspect, | |
# but the code would be very similar. Look at the code in the awesome_print repository | |
# under lib/awesome_print/core_ext/kernel.rb and override the ai method in a similar manner. | |
unless Rails.env.development? # only run when not in development | |
module Kernel | |
def ap(object, level=nil) | |
puts object | |
Rails.logger.info "[ AP called from #{caller(0).last} ]: #{object}" | |
end | |
end | |
# i'm not sure if this line is absolutely necessary, but it works. | |
alias :awesome_print :ap | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment