class-cattr 0.1.0
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 +7 -0
- data/.version +1 -0
- data/lib/class-cattr.rb +3 -0
- data/lib/lib/base.rb +19 -0
- data/lib/lib/proxy.rb +33 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: be11951a79456b009d452a3030e9a7277b759b950d8ec70a20694173f7b82968
|
4
|
+
data.tar.gz: 69c8813e87277f3043e684dacb7fa09799500a14cfa72f6e9d5f851542e1e999
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 857e1997cd1a2c34a30dbd752078d7ee0ea5a41b04965cb84e387c0dc0d9a43e58e9f385eb49dadd41d7192d77cc495ea3497774a3ba0083b09662bd1820cafd
|
7
|
+
data.tar.gz: 284c2b066a3d18fe0ad3fec5faec41501f0eb65f4854497a0e3fb6a2f53b700c857bee4606e29c5dfe8f660143f934959815cbda83b306ef99e42c15475f1270
|
data/.version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/class-cattr.rb
ADDED
data/lib/lib/base.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module ClassCattr
|
2
|
+
def self.included base
|
3
|
+
def base.cattr name=nil
|
4
|
+
if name
|
5
|
+
Proxy.new(self).send(name)
|
6
|
+
else
|
7
|
+
Proxy.new(self)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def cattr name=nil
|
13
|
+
if name
|
14
|
+
Proxy.new(self.class).send(name)
|
15
|
+
else
|
16
|
+
Proxy.new(self.class)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/lib/proxy.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module ClassCattr
|
2
|
+
class Proxy
|
3
|
+
def initialize host
|
4
|
+
@host = host
|
5
|
+
end
|
6
|
+
|
7
|
+
def method_missing key, value=nil, &block
|
8
|
+
name = '@cattr_%s' % key
|
9
|
+
|
10
|
+
if name.sub!(/=$/, '')
|
11
|
+
@host.instance_variable_set name, value
|
12
|
+
else
|
13
|
+
if block_given?
|
14
|
+
@host.instance_variable_set name, block
|
15
|
+
else
|
16
|
+
unless value.nil?
|
17
|
+
raise ArgumentError, 'Plese use setter cattr.%s= to set argument' % key.to_s.sub('=', '')
|
18
|
+
end
|
19
|
+
|
20
|
+
for el in @host.ancestors
|
21
|
+
if el.respond_to?(:superclass) && el != Object && el.instance_variable_defined?(name)
|
22
|
+
value = el.instance_variable_get name
|
23
|
+
value = value.call if value === Proc
|
24
|
+
return value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
raise ArgumentError, 'Cattr class variable "cattr.%s" not defined on "%s".' % [name.sub('@cattr_', ''), @host]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: class-cattr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dino Reic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Class attributes are not natively supported by ruby, this fixes the problem!
|
14
|
+
email: reic.dino@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- "./.version"
|
20
|
+
- "./lib/class-cattr.rb"
|
21
|
+
- "./lib/lib/base.rb"
|
22
|
+
- "./lib/lib/proxy.rb"
|
23
|
+
homepage: https://github.com/dux/class-cattr
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubygems_version: 3.0.6
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Ruby class attributes
|
46
|
+
test_files: []
|