u-attributes 0.6.1 → 0.7.0

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: 903e9c9563fc8f410107e95303233b840956eb91ae28f1582d2e30aea627c0a9
4
- data.tar.gz: 6837229474860fb53ab5253be96dbd51bb1cefa6f376d1c1206a3ff3af834942
3
+ metadata.gz: 17e36e9053fd612a0fdec9ff0d9dd65ffa5b6b5c42cca0cff4855e3547171738
4
+ data.tar.gz: 35f893fa0563d725d386ba98fb65506effaef632ce68a60e144a26671bbd979e
5
5
  SHA512:
6
- metadata.gz: 79f7094cb6d9f0e216725d1ccce60d616624d0537f08b9bbaec63c9dade0fd3439b814fd8b92764ef39688b2ecbc90c44920f54b56ef0086ed375f315f13f889
7
- data.tar.gz: 8a1ef62eba6ac5639d5427b2b375b4a9c4ceffb7d8e465d2ec62f37b66a54033c799a813935b7b457f8c9b899b61ed99e5c34c99009532e9563729e6d27b24d7
6
+ metadata.gz: 69293580d1bde6527d6861cac123adbfe7ad4ace46dc57830a3e4dc980b8052f551c077a73851e1fae08c363915ae2b0544f5dd89ec11913f4ab2734c93b3e06
7
+ data.tar.gz: 8f6c9176e8b2b2f6371a4ec2ccf3b8e7475832b16c1050ee908304e3f3e4502492818bfbc1faa8cd0ffcec8dd26a158a72063fbe8ee128a9ffc1d1db205d11e7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- u-attributes (0.6.0)
4
+ u-attributes (0.7.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 will preserve the parent class attributes #
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
- # Inheritance allows to redefine the attributes default data #
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  module Attributes
5
- VERSION = "0.6.1"
5
+ VERSION = "0.7.0"
6
6
  end
7
7
  end
@@ -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
- self.class.attributes.each_with_object({}) do |name, memo|
62
- if instance_variable_defined?(iv_name = "@#{name}")
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.6.1
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-05 00:00:00.000000000 Z
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.1
84
+ rubygems_version: 3.0.3
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: Define read-only attributes