before_hooks 0.1.1 → 0.1.2
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 +17 -19
- data/lib/before_hooks.rb +40 -28
- data/lib/before_hooks/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: 483373632a92b3bff2aa53fc62123df41f515e08f65eb8921b41eb5e5c959a6a
|
4
|
+
data.tar.gz: '0065946eef8f7597159d8e115c593c69fc6226c904cb7778d856f58d4eb12659'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b44f291f47253c2986607ca564c250a1f4a205572abbf76e0321eedd024807d1f67c40e1395249b89b104e80511c8538c105afd7e58773a94842f9d714bdaf39
|
7
|
+
data.tar.gz: 97357d4c7579f65cf62f3c50e6c9566df92e34d17627ba23bd31016a0c946cf1f9b2c09558c0e169c3dc905a274d56e6ae9593d2afe14a27944dc6dcbfec4cd4
|
data/README.md
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/jrpolidario/before_hooks)
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
Raises error if method already defined to designated `include`, `extend`, or `prepend` base Module/Class.
|
6
|
+
Prevents "silent-failures" and indirect bugs caused by overriding functionality (inter-gems-wide), of which you have no control of.
|
7
|
+
Take note though that this does not let a module/class to be non-overridable.
|
8
|
+
It only promotes and delegates responsibility to the developer to ensure that he/she does not unnecessarily cause "hidden" bugs.
|
9
9
|
|
10
10
|
## Dependencies
|
11
11
|
|
@@ -59,12 +59,12 @@ end
|
|
59
59
|
|
60
60
|
=begin
|
61
61
|
|
62
|
-
SomeModule#before_included
|
62
|
+
"SomeModule#before_included"
|
63
63
|
SomeClass
|
64
|
-
[SomeClass,
|
65
|
-
SomeModule#included
|
64
|
+
[SomeClass, Object, PP::ObjectMixin, Kernel, BasicObject]
|
65
|
+
"SomeModule#included"
|
66
66
|
SomeClass
|
67
|
-
[SomeClass, SomeModule,
|
67
|
+
[SomeClass, SomeModule, Object, PP::ObjectMixin, Kernel, BasicObject]
|
68
68
|
|
69
69
|
=end
|
70
70
|
```
|
@@ -99,29 +99,27 @@ end
|
|
99
99
|
|
100
100
|
=begin
|
101
101
|
|
102
|
-
SomeModule#before_extended
|
102
|
+
"SomeModule#before_extended"
|
103
103
|
SomeClass
|
104
104
|
[#<Class:SomeClass>,
|
105
|
-
BeforeHooks::ClassMethods,
|
106
105
|
#<Class:Object>,
|
107
106
|
#<Class:BasicObject>,
|
108
107
|
Class,
|
109
|
-
Module,
|
110
108
|
BeforeHooks,
|
109
|
+
Module,
|
111
110
|
Object,
|
112
111
|
PP::ObjectMixin,
|
113
112
|
Kernel,
|
114
113
|
BasicObject]
|
115
|
-
SomeModule#extended
|
114
|
+
"SomeModule#extended"
|
116
115
|
SomeClass
|
117
116
|
[#<Class:SomeClass>,
|
118
117
|
SomeModule,
|
119
|
-
BeforeHooks::ClassMethods,
|
120
118
|
#<Class:Object>,
|
121
119
|
#<Class:BasicObject>,
|
122
120
|
Class,
|
123
|
-
Module,
|
124
121
|
BeforeHooks,
|
122
|
+
Module,
|
125
123
|
Object,
|
126
124
|
PP::ObjectMixin,
|
127
125
|
Kernel,
|
@@ -160,18 +158,18 @@ end
|
|
160
158
|
|
161
159
|
=begin
|
162
160
|
|
163
|
-
SomeModule#before_prepended
|
161
|
+
"SomeModule#before_prepended"
|
164
162
|
SomeClass
|
165
|
-
[SomeClass,
|
166
|
-
SomeModule#prepended
|
163
|
+
[SomeClass, Object, PP::ObjectMixin, Kernel, BasicObject]
|
164
|
+
"SomeModule#prepended"
|
167
165
|
SomeClass
|
168
|
-
[SomeModule, SomeClass,
|
166
|
+
[SomeModule, SomeClass, Object, PP::ObjectMixin, Kernel, BasicObject]
|
169
167
|
|
170
168
|
=end
|
171
169
|
```
|
172
170
|
|
173
171
|
## TODOs
|
174
|
-
* Need help or further research on how to support `before_inherited`
|
172
|
+
* Need help or further research on how to support and implement `before_inherited`, `before_method_added`, and `before_method_removed`, because "prepend" trick doesn't readily work with them.
|
175
173
|
|
176
174
|
## Development
|
177
175
|
|
data/lib/before_hooks.rb
CHANGED
@@ -1,42 +1,54 @@
|
|
1
1
|
require 'before_hooks/version'
|
2
2
|
|
3
3
|
module BeforeHooks
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
module ClassMethods
|
10
|
-
def extend(*modules)
|
11
|
-
modules.each do |_module|
|
12
|
-
if _module.singleton_class.instance_methods.include? :before_extended
|
13
|
-
_module.before_extended(self)
|
14
|
-
end
|
4
|
+
def extend(*modules)
|
5
|
+
modules.each do |_module|
|
6
|
+
if _module.singleton_class.instance_methods.include? :before_extended
|
7
|
+
_module.before_extended(self)
|
15
8
|
end
|
16
|
-
|
17
|
-
super
|
18
9
|
end
|
19
10
|
|
20
|
-
|
21
|
-
|
22
|
-
if _module.singleton_class.instance_methods.include? :before_included
|
23
|
-
_module.before_included(self)
|
24
|
-
end
|
25
|
-
end
|
11
|
+
super
|
12
|
+
end
|
26
13
|
|
27
|
-
|
14
|
+
def include(*modules)
|
15
|
+
modules.each do |_module|
|
16
|
+
if _module.singleton_class.instance_methods.include? :before_included
|
17
|
+
_module.before_included(self)
|
18
|
+
end
|
28
19
|
end
|
29
20
|
|
30
|
-
|
31
|
-
|
32
|
-
if _module.singleton_class.instance_methods.include? :before_prepended
|
33
|
-
_module.before_prepended(self)
|
34
|
-
end
|
35
|
-
end
|
21
|
+
super
|
22
|
+
end
|
36
23
|
|
37
|
-
|
24
|
+
def prepend(*modules)
|
25
|
+
modules.each do |_module|
|
26
|
+
if _module.singleton_class.instance_methods.include? :before_prepended
|
27
|
+
_module.before_prepended(self)
|
28
|
+
end
|
38
29
|
end
|
30
|
+
|
31
|
+
super
|
39
32
|
end
|
33
|
+
|
34
|
+
# # TODO: add a `before_method_added` and `before_method_reoved`; not yet working; couldn't yet think of a solution
|
35
|
+
# def method_added(method_name)
|
36
|
+
# puts 'METHOD ADDED!'
|
37
|
+
# puts singleton_class.instance_methods.include? :before_method_added
|
38
|
+
# if singleton_class.instance_methods.include? :before_method_added
|
39
|
+
# before_method_added(args)
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# super
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# def method_removed(*args)
|
46
|
+
# if singleton_class.instance_methods.include? :before_method_removed
|
47
|
+
# before_method_removed(args)
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# super
|
51
|
+
# end
|
40
52
|
end
|
41
53
|
|
42
|
-
|
54
|
+
Module.send(:prepend, BeforeHooks)
|
data/lib/before_hooks/version.rb
CHANGED