clean-annotations 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.version +1 -1
- data/lib/clean-annotations.rb +3 -3
- data/lib/clean-annotations/class_callbacks.rb +11 -9
- 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: 74db9a7090b7480819a19a8cbd8b05b3f8284322b447381c3976f40499a81a78
|
4
|
+
data.tar.gz: ab20371189f91a861308b864344cd9b7c1fa169fa105ff4c0f12a2d6017d8ac3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 287e422e1bb5f4468b579718b3c2973ad52102255875a6f8321f020b787cebb2ddb5d659c219cbfc3d5560627f084d881a5d2a62eef65db14c23b953d9c6224f
|
7
|
+
data.tar.gz: d936ec9f237cd161f284ecaf521e865c522767199410925f77ce4924c0022edb8ec1deb325aa4c1139455f5dcea625f06fcaa8a261934eab7965428b1edc5064
|
data/.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/clean-annotations.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
unless Object.respond_to?(:define_callback)
|
2
|
+
require_relative './clean-annotations/class_callbacks'
|
3
|
+
end
|
4
4
|
|
5
5
|
unless Object.respond_to?(:class_attribute)
|
6
6
|
require_relative './clean-annotations/class_attribute'
|
@@ -1,9 +1,13 @@
|
|
1
1
|
# Rails style callbacks
|
2
2
|
|
3
|
-
class
|
4
|
-
def
|
3
|
+
class Object
|
4
|
+
def define_callback name
|
5
5
|
ivar = "@class_callbacks_#{name}"
|
6
6
|
|
7
|
+
unless is_a?(Class) || is_a?(Module)
|
8
|
+
raise ArgumentError, 'define_callback Can only be defined in a class or a module'
|
9
|
+
end
|
10
|
+
|
7
11
|
define_singleton_method(name) do |method_name=nil, &block|
|
8
12
|
ref = caller[0].split(':in ').first
|
9
13
|
|
@@ -11,13 +15,11 @@ class Class
|
|
11
15
|
self.instance_variable_get(ivar)[ref] = method_name || block
|
12
16
|
end
|
13
17
|
end
|
14
|
-
end
|
15
18
|
|
16
|
-
|
17
|
-
def class_callback name, *args
|
19
|
+
def run_callback name, *args
|
18
20
|
ivar = "@class_callbacks_#{name}"
|
19
21
|
|
20
|
-
list = self.class.ancestors
|
22
|
+
list = is_a?(Class) || is_a?(Module) ? ancestors : self.class.ancestors
|
21
23
|
list = list.slice 0, list.index(Object) if list.index(Object)
|
22
24
|
|
23
25
|
list.reverse.each do |klass|
|
@@ -36,11 +38,11 @@ class Object
|
|
36
38
|
end
|
37
39
|
|
38
40
|
# for controllers, execute from AppController to MainController
|
39
|
-
#
|
41
|
+
# define_callback :before
|
40
42
|
# before do
|
41
43
|
# ...
|
42
44
|
# end
|
43
45
|
# before :method_name
|
44
46
|
# instance = new
|
45
|
-
# instance.
|
46
|
-
# instance.
|
47
|
+
# instance.run_callback :before
|
48
|
+
# instance.run_callback :before, @object
|