u-attributes 0.6.1 → 0.7.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +9 -7
- data/lib/micro/attributes/macros.rb +13 -8
- data/lib/micro/attributes/version.rb +1 -1
- data/lib/micro/attributes.rb +5 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17e36e9053fd612a0fdec9ff0d9dd65ffa5b6b5c42cca0cff4855e3547171738
|
4
|
+
data.tar.gz: 35f893fa0563d725d386ba98fb65506effaef632ce68a60e144a26671bbd979e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69293580d1bde6527d6861cac123adbfe7ad4ace46dc57830a3e4dc980b8052f551c077a73851e1fae08c363915ae2b0544f5dd89ec11913f4ab2734c93b3e06
|
7
|
+
data.tar.gz: 8f6c9176e8b2b2f6371a4ec2ccf3b8e7475832b16c1050ee908304e3f3e4502492818bfbc1faa8cd0ffcec8dd26a158a72063fbe8ee128a9ffc1d1db205d11e7
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -153,11 +153,11 @@ puts other_person.equal?(person) # false
|
|
153
153
|
# Person.new(1)
|
154
154
|
# ArgumentError (argument must be a Hash)
|
155
155
|
|
156
|
-
|
157
|
-
# Inheritance
|
158
|
-
|
156
|
+
################
|
157
|
+
# Inheritance #
|
158
|
+
################
|
159
159
|
|
160
|
-
class Subclass < Person
|
160
|
+
class Subclass < Person # Will preserve the parent class attributes
|
161
161
|
attribute :foo
|
162
162
|
end
|
163
163
|
|
@@ -167,9 +167,11 @@ puts instance.name # John Doe
|
|
167
167
|
puts instance.respond_to?(:age) # true
|
168
168
|
puts instance.respond_to?(:foo) # true
|
169
169
|
|
170
|
-
|
171
|
-
#
|
172
|
-
|
170
|
+
#---------------------------------#
|
171
|
+
# .attribute!() or .attributes!() #
|
172
|
+
#---------------------------------#
|
173
|
+
|
174
|
+
# The methods above allow redefining the attributes default data
|
173
175
|
|
174
176
|
class AnotherSubclass < Person
|
175
177
|
attribute! name: 'Alfa'
|
@@ -36,26 +36,31 @@ module Micro
|
|
36
36
|
__attribute_data!(arg, allow_to_override: false)
|
37
37
|
end
|
38
38
|
|
39
|
-
def attribute!(arg)
|
40
|
-
__attribute_data!(arg, allow_to_override: true)
|
41
|
-
end
|
42
|
-
|
43
39
|
def attributes(*args)
|
44
40
|
return __attributes.to_a if args.empty?
|
45
41
|
|
46
42
|
args.flatten.each { |arg| attribute(arg) }
|
47
43
|
end
|
48
44
|
|
49
|
-
def attributes!(*args)
|
50
|
-
args.flatten.each { |arg| attribute!(arg) }
|
51
|
-
end
|
52
|
-
|
53
45
|
def attributes_data(arg)
|
54
46
|
__attributes_data.merge(
|
55
47
|
Utils.hash_argument!(arg)
|
56
48
|
.each_with_object({}) { |(key, val), memo| memo[key.to_s] = val }
|
57
49
|
)
|
58
50
|
end
|
51
|
+
|
52
|
+
module ForSubclasses
|
53
|
+
def attribute!(arg)
|
54
|
+
__attribute_data!(arg, allow_to_override: true)
|
55
|
+
end
|
56
|
+
|
57
|
+
def attributes!(*args)
|
58
|
+
return args.flatten.each { |arg| attribute!(arg) } unless args.empty?
|
59
|
+
raise ArgumentError, 'wrong number of arguments (given 0, expected 1 or more)'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private_constant :ForSubclasses
|
59
64
|
end
|
60
65
|
end
|
61
66
|
end
|
data/lib/micro/attributes.rb
CHANGED
@@ -21,6 +21,8 @@ module Micro
|
|
21
21
|
self.attributes_data({}).each do |name, value|
|
22
22
|
subclass.attribute(value.nil? ? name : {name => value})
|
23
23
|
end
|
24
|
+
|
25
|
+
subclass.extend Macros.const_get(:ForSubclasses)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -57,12 +59,9 @@ module Micro
|
|
57
59
|
end
|
58
60
|
|
59
61
|
def attributes
|
60
|
-
state =
|
61
|
-
|
62
|
-
|
63
|
-
memo[name] = instance_variable_get(iv_name)
|
64
|
-
end
|
65
|
-
end
|
62
|
+
state = self.class.attributes.each_with_object({}) do |name, memo|
|
63
|
+
memo[name] = public_send(name) if respond_to?(name)
|
64
|
+
end
|
66
65
|
|
67
66
|
self.class.attributes_data(state)
|
68
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: u-attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Serradura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
|
-
rubygems_version: 3.0.
|
84
|
+
rubygems_version: 3.0.3
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: Define read-only attributes
|