clean-annotations 0.1.0 → 0.1.1

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: 8d9303baf6e5dad38ca20584945c4e0c8da1df1b87ea34e0c312eca6dc5723ab
4
- data.tar.gz: 0d9f07d7f5b397b8ca6510f19037c1bf89d76ac53aad20fcf085d676e0943c9f
3
+ metadata.gz: 4a9aaf5121402a2a3a19d2e4aa0e5eb26d3a1cf8bb3aa9e32377bf7a7f38780e
4
+ data.tar.gz: 6dd0855bc5ce65fa2a1360ef703cff2fa427bd63a0b3f674b48b0f87ad883699
5
5
  SHA512:
6
- metadata.gz: 4ad56b523d3c8cc57328853e2d888e323c59e2844e32324681fde6b1051181a9722d66109c2195cde2d06fd7c1ecd3b3d36b2620b9f4a8215bd74898327059e7
7
- data.tar.gz: f63139c6deed120ed6679b8214c35c72687925d643d63c44796f536f76e8428566967321d8281b388b793ab3d8772e71def90bf3e9575688e57ba223604086a3
6
+ metadata.gz: 2727df348b72d4df04c43bdc3671b945d0db5250249170257fe1ef15ffb87d33862ce18f8adc8cdb99b4b3e09d01a75a7631678b36b2e804f4f1309f02ff5cb5
7
+ data.tar.gz: 7db76fb31d58cd3feef260bdd46f36879a5e27fec7ab92c7b564cb6ddaa9dfb8a3f256d923aaeabce054019dfb0e3ea441c9a19ce238a9c688b098a7708f01f7
data/.version CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -1,28 +1,32 @@
1
1
  # Defines class variable
2
2
 
3
- def Object.class_attribute name, default=nil, &block
4
- raise ArgumentError.new('name must be symbol') unless name.is_a?(Symbol)
3
+ class Class
4
+ def class_attribute name, default=nil, &block
5
+ raise ArgumentError.new('name must be symbol') unless name.is_a?(Symbol)
5
6
 
6
- ivar = "@class_attribute_#{name}"
7
+ ivar = "@class_attribute_#{name}"
7
8
 
8
- instance_variable_set ivar, block || default
9
+ instance_variable_set ivar, block || default
9
10
 
10
- define_singleton_method('%s=' % name) { |arg| send(name, arg) }
11
- define_singleton_method(name) do |arg=:_undefined, &block|
12
- # define and set if argument given
13
- if block || arg != :_undefined
14
- return instance_variable_set ivar, block || arg
15
- end
11
+ define_singleton_method('%s=' % name) { |arg| send(name, arg) }
12
+ define_singleton_method(name) do |arg=:_undefined, &block|
13
+ # define and set if argument given
14
+ if block || arg != :_undefined
15
+ return instance_variable_set ivar, block || arg
16
+ end
16
17
 
17
- # find value and return
18
- ancestors.each do |klass|
19
- if klass.instance_variable_defined?(ivar)
20
- value = klass.instance_variable_get ivar
21
- return value.is_a?(Proc) ? instance_exec(&value) : value
18
+ # find value and return
19
+ ancestors.each do |klass|
20
+ if klass.instance_variable_defined?(ivar)
21
+ value = klass.instance_variable_get ivar
22
+ return value.is_a?(Proc) ? instance_exec(&value) : value
23
+ end
22
24
  end
23
25
  end
24
26
  end
27
+ end
25
28
 
29
+ class Object
26
30
  def class_attribute name
27
31
  self.class.send(name)
28
32
  end
@@ -1,34 +1,33 @@
1
1
  # Rails style callbacks
2
2
 
3
- class Object
4
- def class_callback name, arg=nil
5
- Object.class_callback name, self, arg
6
- end
7
-
8
- def self.class_callback name, context=nil, arg=nil
3
+ class Class
4
+ def class_callback name
9
5
  ivar = "@class_callbacks_#{name}"
10
6
 
11
- unless context
12
- define_singleton_method(name) do |method_name=nil, &block|
13
- ref = caller[0].split(':in ').first
7
+ define_singleton_method(name) do |method_name=nil, &block|
8
+ ref = caller[0].split(':in ').first
14
9
 
15
- self.instance_variable_set(ivar, {}) unless instance_variable_defined?(ivar)
16
- self.instance_variable_get(ivar)[ref] = method_name || block
17
- end
10
+ self.instance_variable_set(ivar, {}) unless instance_variable_defined?(ivar)
11
+ self.instance_variable_get(ivar)[ref] = method_name || block
12
+ end
13
+ end
14
+ end
15
+
16
+ class Object
17
+ def class_callback name, *args
18
+ ivar = "@class_callbacks_#{name}"
18
19
 
19
- else
20
- list = context.respond_to?(:const_missing) && context.respond_to?(:ancestors) ? context.ancestors : context.class.ancestors
21
- list = list.slice 0, list.index(Object) if list.index(Object)
20
+ list = self.class.ancestors
21
+ list = list.slice 0, list.index(Object) if list.index(Object)
22
22
 
23
- list.reverse.each do |klass|
24
- if klass.instance_variable_defined?(ivar)
25
- mlist = klass.instance_variable_get(ivar).values
26
- mlist.each do |m|
27
- if m.is_a?(Symbol)
28
- context.send m
29
- else
30
- context.instance_exec arg, &m
31
- end
23
+ list.reverse.each do |klass|
24
+ if klass.instance_variable_defined?(ivar)
25
+ mlist = klass.instance_variable_get(ivar).values
26
+ mlist.each do |m|
27
+ if m.is_a?(Symbol)
28
+ send m, *args
29
+ else
30
+ instance_exec *args, &m
32
31
  end
33
32
  end
34
33
  end
@@ -43,5 +42,5 @@ end
43
42
  # end
44
43
  # before :method_name
45
44
  # instance = new
46
- # instance.class_callback :before,
47
- # instance.class_callback :before, arg
45
+ # instance.class_callback :before
46
+ # instance.class_callback :before, @arg
@@ -55,22 +55,24 @@ end
55
55
  # opts
56
56
  # end
57
57
 
58
- # name "Test method desc"
58
+ # name "Test method desc 1"
59
+ # name "Test method desc 2"
59
60
  # param :email, :email
60
61
  # def test
61
62
  # end
62
63
  # end
63
64
 
64
- # ap Foo.method_attr
65
+ # Foo.method_attr
65
66
  # {
66
- # "test": {
67
- # "name": [
68
- # "Test method desc"
67
+ # test: {
68
+ # name: [
69
+ # "Test method desc 1",
70
+ # "Test method desc 2"
69
71
  # ],
70
- # "param": [
72
+ # param: [
71
73
  # {
72
- # "name": "email",
73
- # "type": "String"
74
+ # name: :email,
75
+ # type: String
74
76
  # }
75
77
  # ]
76
78
  # }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clean-annotations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Reic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-09 00:00:00.000000000 Z
11
+ date: 2019-12-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Define annotatable attribute names and assign them to methods or classes,
14
14
  add callbacks to non-Rails classes. Void of dependencies.