Created
January 26, 2013 09:20
-
-
Save flash-gordon/4641262 to your computer and use it in GitHub Desktop.
Little object extension that provide method calling tracking
This file contains hidden or 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
class Object | |
# class MyObject | |
# end | |
# | |
# obj = MyObject.new | |
# obj.ring_it! # Start tracking | |
# # Logs will appear in rails log (tweak as you wish) | |
# # Do not use in production! Only for debug | |
def ring_it! | |
return if @__ringed__ | |
raise ArgumentError, 'Only objects with eigenclass allowed' if Symbol === self || Fixnum === self | |
class_name = self.class.name | |
object_id = self.object_id | |
(methods - [:ring_it!, :caller, :instance_eval, :method]).each do |method_name| | |
method = method(method_name) | |
src_location = method.source_location || [nil, nil] | |
instance_eval(<<-EVAL, *src_location.compact) | |
def #{method_name}(*args) | |
Rails.logger.info(caller.first + " - Object ringing. Object #{class_name}##{object_id}. Method: :#{method_name}. Arguments: " + args.inspect) | |
super | |
end | |
EVAL | |
end | |
@__ringed__ = true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment