class-cattr 0.1.0 → 0.1.1
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/.version +1 -1
- data/lib/lib/base.rb +10 -10
- data/lib/lib/proxy.rb +21 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccb3dc6c7369858e4d43b7fa162ca5b707aec8e247f7e150bdf3efaef515455a
|
4
|
+
data.tar.gz: 3e28d1f02f7ec13eeee2ff0c4e29c01910e7f6a572d753cb6e43a226304ce3a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1ab1daf0a53f6571443f9b48e5590ae93947f16073af76b3424819d63c725f835b6685f49728ca4cf4550a5c341e321523d7716b57cee79780404d6955c7d19
|
7
|
+
data.tar.gz: 49b3239f768cdce323bbb7401531e94ac4935776e51a503b9dd88b71db03d2f587a829dfed63f0f14ce318bc9ca692e5870d45127bb9fffee038053b7d1ee602
|
data/.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/lib/base.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
|
2
|
-
def
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Proxy.new(self)
|
8
|
-
end
|
1
|
+
class Class
|
2
|
+
def cattr name=nil
|
3
|
+
if name
|
4
|
+
CattrProxy.new(self).send('%s=' % name, nil)
|
5
|
+
else
|
6
|
+
CattrProxy.new(self)
|
9
7
|
end
|
10
8
|
end
|
9
|
+
end
|
11
10
|
|
11
|
+
class Object
|
12
12
|
def cattr name=nil
|
13
13
|
if name
|
14
|
-
|
14
|
+
CattrProxy.new(self.class).send(name)
|
15
15
|
else
|
16
|
-
|
16
|
+
CattrProxy.new(self.class)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/lib/proxy.rb
CHANGED
@@ -1,32 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end
|
1
|
+
class CattrProxy
|
2
|
+
def initialize host
|
3
|
+
@host = host
|
4
|
+
end
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
def method_missing key, value=nil, &block
|
7
|
+
name = '@cattr_%s' % key
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
if name.sub!(/=$/, '')
|
10
|
+
@host.instance_variable_set name, value
|
11
|
+
else
|
12
|
+
if block_given?
|
13
|
+
@host.instance_variable_set name, block
|
12
14
|
else
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
unless value.nil?
|
17
|
-
raise ArgumentError, 'Plese use setter cattr.%s= to set argument' % key.to_s.sub('=', '')
|
18
|
-
end
|
15
|
+
unless value.nil?
|
16
|
+
raise ArgumentError, 'Plese use setter cattr.%s= to set argument' % key.to_s.sub('=', '')
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
19
|
+
for el in @host.ancestors
|
20
|
+
if el.respond_to?(:superclass) && el != Object && el.instance_variable_defined?(name)
|
21
|
+
value = el.instance_variable_get name
|
22
|
+
value = value.call if value === Proc
|
23
|
+
return value
|
26
24
|
end
|
27
|
-
|
28
|
-
raise ArgumentError, 'Cattr class variable "cattr.%s" not defined on "%s".' % [name.sub('@cattr_', ''), @host]
|
29
25
|
end
|
26
|
+
|
27
|
+
raise ArgumentError, 'Cattr class variable "cattr.%s" not defined on "%s".' % [name.sub('@cattr_', ''), @host]
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: class-cattr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
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: 2021-
|
11
|
+
date: 2021-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Class attributes are not natively supported by ruby, this fixes the problem!
|
14
14
|
email: reic.dino@gmail.com
|