pachinko 0.0.2 → 0.0.3
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/lib/pachinko.rb +14 -10
- metadata +1 -1
data/lib/pachinko.rb
CHANGED
@@ -12,11 +12,11 @@ require 'ansi'
|
|
12
12
|
# def relevant?
|
13
13
|
# !defined?(FabricatedClass)
|
14
14
|
# end
|
15
|
-
# #
|
15
|
+
# # patch: a method which you pass a block which applies the patch
|
16
16
|
# # Reason for this is that you can't reopen classes in methods...
|
17
|
-
#
|
17
|
+
# patch do
|
18
18
|
# class ::FabricatedClass; end
|
19
|
-
#
|
19
|
+
# end
|
20
20
|
# end
|
21
21
|
|
22
22
|
class Pachinko
|
@@ -37,29 +37,33 @@ class Pachinko
|
|
37
37
|
|
38
38
|
class << self
|
39
39
|
attr_accessor :last_patch
|
40
|
+
attr_reader :patch_block
|
41
|
+
|
42
|
+
def patch(&block)
|
43
|
+
@patch_block = block
|
44
|
+
end
|
40
45
|
|
41
46
|
def run(*args)
|
42
47
|
new.run(*args)
|
43
48
|
end
|
44
|
-
|
49
|
+
|
45
50
|
def development_mode?
|
46
|
-
defined?(Rails) && defined?(::Rails.env) && ::Rails.env.development?
|
51
|
+
defined?(::Rails) && defined?(::Rails.env) && ::Rails.env.development?
|
47
52
|
end
|
53
|
+
|
48
54
|
def test_mode?
|
49
|
-
if defined?(Rails) && defined?(::Rails.env)
|
55
|
+
if defined?(::Rails) && defined?(::Rails.env)
|
50
56
|
::Rails.env.test?
|
51
57
|
else
|
52
58
|
true
|
53
59
|
end
|
54
60
|
end
|
61
|
+
|
55
62
|
def last_results
|
56
63
|
last_patch.results
|
57
64
|
end
|
58
65
|
end
|
59
66
|
|
60
|
-
# Allows you to prioritize certain patch files first, such as core object patches
|
61
|
-
PATCH_PRIORITY = lambda { |p| p =~ /\/(hash|string|array|object)/i ? ' ' : p }
|
62
|
-
|
63
67
|
def name
|
64
68
|
raise NotImplementedError, "Your patch doesn't define a 'name' method... please override in your patch class"
|
65
69
|
end
|
@@ -109,7 +113,7 @@ class Pachinko
|
|
109
113
|
private
|
110
114
|
def apply
|
111
115
|
begin
|
112
|
-
self.class
|
116
|
+
self.class.patch_block.call
|
113
117
|
rescue NameError => e
|
114
118
|
e.message << "\nNOTE TO PATCH DEVS: If you are writing a patch, it is possible that you just have to root-namespace any relevant classes in your PATCH block with a double colon (::) in front, to avoid this error!"
|
115
119
|
raise e
|