zimbatm-monkeypatch 0.1.0 → 0.1.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/README.rdoc +14 -4
- data/example/patch_usage.rb +5 -4
- data/lib/monkeypatch.rb +1 -1
- data/task/gem.rake +10 -9
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
= MonkeyPatch
|
2
2
|
|
3
|
+
*WARNING: This is alpha code, the API is not stable yet.*
|
4
|
+
|
3
5
|
<INSERT NICE INTRO HERE>
|
4
6
|
|
5
7
|
Do you monkeys, patch ? If so, use this library, you won't regret it.
|
@@ -12,22 +14,30 @@
|
|
12
14
|
|
13
15
|
</INSERT NICE INTRO HERE>
|
14
16
|
|
15
|
-
|
17
|
+
Authors:: [ zimbatm <zimbatm@oree.ch> ]
|
18
|
+
|
19
|
+
== Getting started
|
16
20
|
|
17
21
|
Example usage:
|
18
22
|
|
19
23
|
:include:example/patch_usage.rb
|
20
24
|
|
21
|
-
|
25
|
+
Look at the MonkeyPatch module to get an idea of the API.
|
26
|
+
|
27
|
+
Once you have a patch object, look at the MonkeyPatch::Patch definition to know how to use it.
|
28
|
+
|
29
|
+
----
|
30
|
+
|
31
|
+
==== Related projects
|
22
32
|
|
23
33
|
* http://github.com/coderrr/monkey_shield/ : provides sorts of namespaces to avoid patch collision
|
24
34
|
|
25
|
-
|
35
|
+
==== Ideas
|
26
36
|
|
27
37
|
* method re-definition or module/class extension could be detected, especially when using Gems. The load-path is not the same between the original definition and the new-one.
|
28
38
|
* load-path as namespace
|
29
39
|
|
30
|
-
|
40
|
+
==== TODO
|
31
41
|
|
32
42
|
* Add programmable patching conditions
|
33
43
|
* Add reason string
|
data/example/patch_usage.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'monkeypatch'
|
2
2
|
|
3
3
|
# Define a new extension that adds the #to_blob method
|
4
|
-
|
4
|
+
blob_patch = MonkeyPatch.add_method(:to_blob) do
|
5
5
|
def to_blob; "<blob>" end
|
6
6
|
end
|
7
7
|
|
8
8
|
x = "something"
|
9
|
-
|
9
|
+
blob_patch.patch_instance(x)
|
10
10
|
x.to_blob #=> "<blob>"
|
11
11
|
|
12
12
|
# Define a patch, that replaces the #to_date method
|
13
|
-
|
13
|
+
str_patch = MonkeyPatch.replace_method(:to_s) do
|
14
14
|
def to_s; "..." end
|
15
15
|
end
|
16
16
|
|
@@ -18,7 +18,8 @@ class ExampleClass
|
|
18
18
|
def to_s; "hello" end
|
19
19
|
end
|
20
20
|
|
21
|
-
(
|
21
|
+
(blob_patch & str_patch).patch_class(ExampleClass)
|
22
22
|
|
23
23
|
ExampleClass.new.to_s #=> "..."
|
24
24
|
ExampleClass.new.to_blob #=> "<blob>"
|
25
|
+
|
data/lib/monkeypatch.rb
CHANGED
@@ -7,7 +7,7 @@ Once you have a patch, look at Patch and it's children to see how to use it.
|
|
7
7
|
=end
|
8
8
|
module MonkeyPatch
|
9
9
|
# MonkeyPatch's version as a string
|
10
|
-
VERSION = '0.1.
|
10
|
+
VERSION = '0.1.1'
|
11
11
|
# May be raised on check_conflicts
|
12
12
|
class ConflictError < StandardError; end
|
13
13
|
|
data/task/gem.rake
CHANGED
@@ -15,22 +15,23 @@ spec = Gem::Specification.new do |s|
|
|
15
15
|
s.test_files = FileList['test/test*.rb']
|
16
16
|
end
|
17
17
|
|
18
|
-
file "ruby-monkeypatch.gemspec" do |t|
|
19
|
-
File.open(t.name, 'w') do |f|
|
20
|
-
f.write(spec.to_ruby)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
18
|
Rake::GemPackageTask.new(spec) do |pkg|
|
25
19
|
# pkg.need_zip = true
|
26
20
|
# pkg.need_tar = true
|
27
21
|
end
|
22
|
+
task :gem => "gem:spec"
|
28
23
|
|
29
24
|
namespace :gem do
|
30
|
-
|
25
|
+
|
26
|
+
spec_name = "ruby-monkeypatch.gemspec"
|
27
|
+
desc "Updates the #{spec_name} file if VERSION has changed"
|
31
28
|
task :spec do
|
32
|
-
File.
|
33
|
-
|
29
|
+
if !File.exist?(spec_name) ||
|
30
|
+
eval(File.read(spec_name)).version.to_s != MonkeyPatch::VERSION
|
31
|
+
File.open(spec_name, 'w') do |f|
|
32
|
+
f.write(spec.to_ruby)
|
33
|
+
end
|
34
|
+
STDOUT.puts "*** Gem specification updated ***"
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|