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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/lib/lib/base.rb +10 -10
  4. data/lib/lib/proxy.rb +21 -23
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be11951a79456b009d452a3030e9a7277b759b950d8ec70a20694173f7b82968
4
- data.tar.gz: 69c8813e87277f3043e684dacb7fa09799500a14cfa72f6e9d5f851542e1e999
3
+ metadata.gz: ccb3dc6c7369858e4d43b7fa162ca5b707aec8e247f7e150bdf3efaef515455a
4
+ data.tar.gz: 3e28d1f02f7ec13eeee2ff0c4e29c01910e7f6a572d753cb6e43a226304ce3a9
5
5
  SHA512:
6
- metadata.gz: 857e1997cd1a2c34a30dbd752078d7ee0ea5a41b04965cb84e387c0dc0d9a43e58e9f385eb49dadd41d7192d77cc495ea3497774a3ba0083b09662bd1820cafd
7
- data.tar.gz: 284c2b066a3d18fe0ad3fec5faec41501f0eb65f4854497a0e3fb6a2f53b700c857bee4606e29c5dfe8f660143f934959815cbda83b306ef99e42c15475f1270
6
+ metadata.gz: d1ab1daf0a53f6571443f9b48e5590ae93947f16073af76b3424819d63c725f835b6685f49728ca4cf4550a5c341e321523d7716b57cee79780404d6955c7d19
7
+ data.tar.gz: 49b3239f768cdce323bbb7401531e94ac4935776e51a503b9dd88b71db03d2f587a829dfed63f0f14ce318bc9ca692e5870d45127bb9fffee038053b7d1ee602
data/.version CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/lib/base.rb CHANGED
@@ -1,19 +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
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
- Proxy.new(self.class).send(name)
14
+ CattrProxy.new(self.class).send(name)
15
15
  else
16
- Proxy.new(self.class)
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
- module ClassCattr
2
- class Proxy
3
- def initialize host
4
- @host = host
5
- end
1
+ class CattrProxy
2
+ def initialize host
3
+ @host = host
4
+ end
6
5
 
7
- def method_missing key, value=nil, &block
8
- name = '@cattr_%s' % key
6
+ def method_missing key, value=nil, &block
7
+ name = '@cattr_%s' % key
9
8
 
10
- if name.sub!(/=$/, '')
11
- @host.instance_variable_set name, value
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
- 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
15
+ unless value.nil?
16
+ raise ArgumentError, 'Plese use setter cattr.%s= to set argument' % key.to_s.sub('=', '')
17
+ end
19
18
 
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
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.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: 2021-02-21 00:00:00.000000000 Z
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