monkey_patcher
Dead simple - not so useful gem helping you keep track of your monkey patches. In other words, this gem lets you keep track of modifications made on some “base” code, classes/methods tempered with can be easily found and the modifying code can be spotted.
Example:
require 'monkey_patcher'
# base code
class Foo
def ; 'original Foo#bar'; end
end
# monkey patch #1
class Foo
include MonkeyPatcher
monkey_trace("Reopening Foo to add a couple methods necessary for the README",
File.(__FILE__))
def self.; 'class method bar'; end
def ; 'modified Foo#bar'; end
def baz; 'added Foo#baz'; end
end
# monkey patch #2
class Foo
include MonkeyPatcher
monkey_trace("Just to show it works",
File.(__FILE__))
def ; 'patched another time'; end
end
puts "Foo was tempered" if Foo.monkey_patched?
puts Foo.patched_methods
puts Foo.patched_methods.first.desc
Output:
Foo was tempered
Foo.bar - patched in /Users/mattetti/Desktop/test.rb - Reopening Foo to add a couple methods necessary for the README
bar - patched in /Users/mattetti/Desktop/test.rb - Reopening Foo to add a couple methods necessary for the README
baz - patched in /Users/mattetti/Desktop/test.rb - Reopening Foo to add a couple methods necessary for the README
bar - patched in /Users/mattetti/Desktop/test.rb - Just to show it works
Misc
The description and origin of the patch are cached in the modified class, if the same class is reopened without defining a new description and origin, the previously settings will be used. So if you see a method monkey patched 5 times in the same file when you really only monkey patched once, that means that the file was modified in other ‘untraced’ places.
Note on Patches/Pull Requests
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright
Copyright © 2010 Matt Aimonetti. See LICENSE for details.