monkey_patcher 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Matt Aimonetti
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ = monkey_patcher
2
+
3
+ Dead simple - not so useful gem helping you keep track of your monkey patches.
4
+ 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.
5
+
6
+ == Example:
7
+
8
+ require 'monkey_patcher'
9
+
10
+ # base code
11
+ class Foo
12
+ def bar; 'original Foo#bar'; end
13
+ end
14
+
15
+ # monkey patch #1
16
+ class Foo
17
+ include MonkeyPatcher
18
+ monkey_trace("Reopening Foo to add a couple methods necessary for the README",
19
+ File.expand_path(__FILE__))
20
+
21
+ def self.bar; 'class method bar'; end
22
+ def bar; 'modified Foo#bar'; end
23
+ def baz; 'added Foo#baz'; end
24
+ end
25
+
26
+ # monkey patch #2
27
+ class Foo
28
+ include MonkeyPatcher
29
+ monkey_trace("Just to show it works",
30
+ File.expand_path(__FILE__))
31
+ def bar; 'patched another time'; end
32
+ end
33
+
34
+ puts "Foo was tempered" if Foo.monkey_patched?
35
+ puts Foo.patched_methods
36
+ puts Foo.patched_methods.first.desc
37
+
38
+ === Output:
39
+
40
+ Foo was tempered
41
+ Foo.bar - patched in /Users/mattetti/Desktop/test.rb - Reopening Foo to add a couple methods necessary for the README
42
+ bar - patched in /Users/mattetti/Desktop/test.rb - Reopening Foo to add a couple methods necessary for the README
43
+ baz - patched in /Users/mattetti/Desktop/test.rb - Reopening Foo to add a couple methods necessary for the README
44
+ bar - patched in /Users/mattetti/Desktop/test.rb - Just to show it works
45
+
46
+ == Misc
47
+
48
+ 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.
49
+
50
+ == Note on Patches/Pull Requests
51
+
52
+ * Fork the project.
53
+ * Make your feature addition or bug fix.
54
+ * Add tests for it. This is important so I don't break it in a
55
+ future version unintentionally.
56
+ * Commit, do not mess with rakefile, version, or history.
57
+ (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)
58
+ * Send me a pull request. Bonus points for topic branches.
59
+
60
+ == Copyright
61
+
62
+ Copyright (c) 2010 Matt Aimonetti. See LICENSE for details.
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "monkey_patcher"
8
+ gem.summary = %Q{Dead simple - not so useful gem helping you keep track of your monkey patches.}
9
+ gem.description = %Q{Keep track of where you monkey patch your code.}
10
+ gem.email = "mattaimonetti@gmail.com"
11
+ gem.homepage = "http://github.com/mattetti/monkey_patcher"
12
+ gem.authors = ["Matt Aimonetti"]
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/test_*.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ task :test => :check_dependencies
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "monkey_patcher #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,54 @@
1
+ class Object
2
+ def self.monkey_patched?
3
+ self.respond_to?(:patched_methods) && !patched_methods.empty?
4
+ end
5
+ end
6
+
7
+ module MonkeyPatcher
8
+ def self.included(base)
9
+ base.extend(ClassMethods)
10
+ end
11
+
12
+ class AppendedMethodInfo
13
+ attr_accessor :name, :desc, :origin
14
+ def to_s
15
+ "#{name} - patched in #{origin || 'an untraced file'} - #{desc}"
16
+ end
17
+ end
18
+
19
+ module ClassMethods
20
+ def monkey_trace(desc, file_path=nil)
21
+ @desc = desc
22
+ @current_monkey_patch_file = file_path
23
+ end
24
+
25
+ def patched_methods
26
+ @patched_methods || []
27
+ end
28
+
29
+ def method_added(method_name)
30
+ log_monkey_patch(method_name)
31
+ # call super in case someone else is hooking into the method addition
32
+ super
33
+ end
34
+
35
+ def singleton_method_added(method_name)
36
+ log_monkey_patch(method_name, true)
37
+ # call super in case someone else is hooking into the method addition
38
+ super
39
+ end
40
+
41
+ private
42
+
43
+ def log_monkey_patch(method_name, klass_meth=false)
44
+ a_meth = AppendedMethodInfo.new
45
+ a_meth.name = klass_meth ? "#{name}.#{method_name}" : method_name
46
+ a_meth.origin = @current_monkey_patch_file
47
+ a_meth.desc = @desc
48
+
49
+ @patched_methods ||= []
50
+ @patched_methods << a_meth
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,51 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{monkey_patcher}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Matt Aimonetti"]
12
+ s.date = %q{2010-06-06}
13
+ s.description = %q{Keep track of where you monkey patch your code.}
14
+ s.email = %q{mattaimonetti@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "lib/monkey_patcher.rb",
25
+ "monkey_patcher.gemspec",
26
+ "test/example.rb",
27
+ "test/helper.rb",
28
+ "test/test_monkey_patcher.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/mattetti/monkey_patcher}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.5}
34
+ s.summary = %q{Dead simple - not so useful gem helping you keep track of your monkey patches.}
35
+ s.test_files = [
36
+ "test/example.rb",
37
+ "test/helper.rb",
38
+ "test/test_monkey_patcher.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ else
47
+ end
48
+ else
49
+ end
50
+ end
51
+
@@ -0,0 +1,25 @@
1
+ require_relative '../lib/monkey_patcher'
2
+
3
+ class Foo
4
+ def bar; 'original Foo#bar'; end
5
+ end
6
+
7
+ class Foo
8
+ include MonkeyPatcher
9
+ monkey_trace("Reopening Foo to add a couple methods necessary for the README",
10
+ File.expand_path(__FILE__))
11
+
12
+ def self.bar; 'class method bar'; end
13
+ def bar; 'modified Foo#bar'; end
14
+ def baz; 'added Foo#baz'; end
15
+ end
16
+
17
+ class Foo
18
+ include MonkeyPatcher
19
+ monkey_trace("Just to show it works",
20
+ File.expand_path(__FILE__))
21
+ def bar; 'patched another time'; end
22
+ end
23
+
24
+ puts "Foo was tempered" if Foo.monkey_patched?
25
+ puts Foo.patched_methods
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'monkey_patcher'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestMonkeyPatcher < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monkey_patcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matt Aimonetti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-06-06 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Keep track of where you monkey patch your code.
17
+ email: mattaimonetti@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - LICENSE
27
+ - README.rdoc
28
+ - Rakefile
29
+ - VERSION
30
+ - lib/monkey_patcher.rb
31
+ - monkey_patcher.gemspec
32
+ - test/example.rb
33
+ - test/helper.rb
34
+ - test/test_monkey_patcher.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/mattetti/monkey_patcher
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.5
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Dead simple - not so useful gem helping you keep track of your monkey patches.
63
+ test_files:
64
+ - test/example.rb
65
+ - test/helper.rb
66
+ - test/test_monkey_patcher.rb