finalist 0.1.2 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +30 -0
- data/lib/finalist.rb +25 -9
- data/lib/finalist/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c16358bc0a05975770702b6234cbb3c03f457fb4a1fd5ec707e0c87106247b50
|
4
|
+
data.tar.gz: 8da986b8a9c507c4dfb5bf200d3b92e59ac2cc7a1925f8202e49d8968cab87b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2884650dd911c2667fa754e6fe6a35834b6704ea7081803ba5a34d7e0585899572fe351da5854cf57fac1d7fecbbc87227ff8b80586d74a51c5fc3214c31ed02
|
7
|
+
data.tar.gz: 01bd8655ba387ef3a885adfa44e9b345f49d8b5af7fed03a7369652114284fc295d18dcdadc01d11f04423f6c234c2fddbd3ebfcce4ceaeb71a794b3be6dfd8c
|
data/README.md
CHANGED
@@ -47,6 +47,10 @@ A class or module extends `Finalist` module
|
|
47
47
|
And add `final` modifier to target method.
|
48
48
|
(`final` can accept symbol as method name.)
|
49
49
|
|
50
|
+
### for Production
|
51
|
+
If you want to disable Finalist, write `Finalist.disable = true` at first line.
|
52
|
+
If Finalist is disabled, TracePoint never runs, and so there is no overhead of VM instruction.
|
53
|
+
|
50
54
|
### Examples
|
51
55
|
|
52
56
|
#### include module
|
@@ -181,6 +185,32 @@ class L2
|
|
181
185
|
end
|
182
186
|
```
|
183
187
|
|
188
|
+
#### overrided by module prepend
|
189
|
+
|
190
|
+
This case is a intended loophole.
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
module M1
|
194
|
+
extend Finalist
|
195
|
+
|
196
|
+
final def foo
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
module M3
|
201
|
+
def foo
|
202
|
+
"foo"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
class M2
|
207
|
+
include M1
|
208
|
+
prepend M3
|
209
|
+
end
|
210
|
+
|
211
|
+
M2.new.foo # => "foo"
|
212
|
+
```
|
213
|
+
|
184
214
|
## How is this implemented?
|
185
215
|
|
186
216
|
Use so many ruby hooks. `method_added` and `singleton_method_added` and `included` and `extended`.
|
data/lib/finalist.rb
CHANGED
@@ -14,11 +14,27 @@ module Finalist
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
@disable = false
|
18
|
+
|
19
|
+
def self.disable=(v)
|
20
|
+
@disable = v
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.disabled?
|
24
|
+
@disable
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.enabled?
|
28
|
+
!disabled?
|
29
|
+
end
|
30
|
+
|
17
31
|
def self.extended(base)
|
18
32
|
super
|
19
33
|
base.extend(SyntaxMethods)
|
20
34
|
base.singleton_class.extend(SyntaxMethods)
|
21
|
-
|
35
|
+
if enabled?
|
36
|
+
base.extend(ModuleMethods) if base.is_a?(Module)
|
37
|
+
end
|
22
38
|
end
|
23
39
|
|
24
40
|
def self.finalized_methods
|
@@ -29,15 +45,9 @@ module Finalist
|
|
29
45
|
def included(base)
|
30
46
|
super
|
31
47
|
|
32
|
-
|
48
|
+
return if Finalist.disabled?
|
33
49
|
|
34
|
-
|
35
|
-
event_type =
|
36
|
-
if caller_info.label.match?(/block/)
|
37
|
-
:b_return
|
38
|
-
else
|
39
|
-
:end
|
40
|
-
end
|
50
|
+
base.extend(Finalist)
|
41
51
|
|
42
52
|
base.ancestors.drop(1).each do |mod|
|
43
53
|
Finalist.finalized_methods[mod]&.each do |fmeth_name|
|
@@ -59,6 +69,8 @@ module Finalist
|
|
59
69
|
def base.singleton_method_added(symbol)
|
60
70
|
super
|
61
71
|
|
72
|
+
return if Finalist.disabled?
|
73
|
+
|
62
74
|
meth = singleton_class.instance_method(symbol)
|
63
75
|
super_method = meth.super_method
|
64
76
|
while super_method
|
@@ -95,6 +107,8 @@ module Finalist
|
|
95
107
|
def method_added(symbol)
|
96
108
|
super
|
97
109
|
|
110
|
+
return if Finalist.disabled?
|
111
|
+
|
98
112
|
meth = instance_method(symbol)
|
99
113
|
super_method = meth.super_method
|
100
114
|
while super_method
|
@@ -108,6 +122,8 @@ module Finalist
|
|
108
122
|
def singleton_method_added(symbol)
|
109
123
|
super
|
110
124
|
|
125
|
+
return if Finalist.disabled?
|
126
|
+
|
111
127
|
meth = singleton_class.instance_method(symbol)
|
112
128
|
super_method = meth.super_method
|
113
129
|
while super_method
|
data/lib/finalist/version.rb
CHANGED