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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a9aaf5121402a2a3a19d2e4aa0e5eb26d3a1cf8bb3aa9e32377bf7a7f38780e
4
- data.tar.gz: 6dd0855bc5ce65fa2a1360ef703cff2fa427bd63a0b3f674b48b0f87ad883699
3
+ metadata.gz: 74db9a7090b7480819a19a8cbd8b05b3f8284322b447381c3976f40499a81a78
4
+ data.tar.gz: ab20371189f91a861308b864344cd9b7c1fa169fa105ff4c0f12a2d6017d8ac3
5
5
  SHA512:
6
- metadata.gz: 2727df348b72d4df04c43bdc3671b945d0db5250249170257fe1ef15ffb87d33862ce18f8adc8cdb99b4b3e09d01a75a7631678b36b2e804f4f1309f02ff5cb5
7
- data.tar.gz: 7db76fb31d58cd3feef260bdd46f36879a5e27fec7ab92c7b564cb6ddaa9dfb8a3f256d923aaeabce054019dfb0e3ea441c9a19ce238a9c688b098a7708f01f7
6
+ metadata.gz: 287e422e1bb5f4468b579718b3c2973ad52102255875a6f8321f020b787cebb2ddb5d659c219cbfc3d5560627f084d881a5d2a62eef65db14c23b953d9c6224f
7
+ data.tar.gz: d936ec9f237cd161f284ecaf521e865c522767199410925f77ce4924c0022edb8ec1deb325aa4c1139455f5dcea625f06fcaa8a261934eab7965428b1edc5064
data/.version CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -1,6 +1,6 @@
1
- require_relative './clean-annotations/class_callbacks'
2
-
3
- # do not load if allready defined
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 Class
4
- def class_callback name
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
- class Object
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
- # class_callback :before
41
+ # define_callback :before
40
42
  # before do
41
43
  # ...
42
44
  # end
43
45
  # before :method_name
44
46
  # instance = new
45
- # instance.class_callback :before
46
- # instance.class_callback :before, @arg
47
+ # instance.run_callback :before
48
+ # instance.run_callback :before, @object
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clean-annotations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Reic