u-attributes 0.4.0 → 0.5.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: 724654639b33deda5424bc5e0ac320ff1a79c34aa1aed860aa9aa18ac77830be
4
- data.tar.gz: 44c63295b620dd096b08aefe3b6d62604a09d857ff1541f74829f0df59076937
3
+ metadata.gz: f28992fcd550ab8d700f8d722af72a486c84cdc5cb5d8fd526dd653d0f88ffb9
4
+ data.tar.gz: 9896e8b25b7abcb11503bd0f11f91ddcb4f0bcfcbbe6a5467928a791da7f8d6f
5
5
  SHA512:
6
- metadata.gz: c9ad9a87ec9c9999f311e8f655c6ac186928718ea24fffd017173c78b2611c8879d7ae2f4011f835505f1cf73decb47a9e1b7566c134b5534fe4214606b7c00b
7
- data.tar.gz: 9eec234c824538f536e2cd329034ca4954c9770b78c8f144da0b0e87ee84fc1979e7345e9d06e48936805d1bf3ec870c3ef74e693793938c2edd83fb73655da4
6
+ metadata.gz: a77934dec03187c8b45ff2c9e1577472dc7b2a7633cae3edec6c2a9d093acb35262f10e625ffb8ac086d949f41f8a0b1d46f1e57df585b03d0f9b51b72a2ff53
7
+ data.tar.gz: bd186e19af413b6bf26943fe4b527f285725b947226a65bc11ac35b5909883515e09267a11bbbe812e941d3aebb586c4535d406d0f7c2f6079fa42f1346ea82d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- u-attributes (0.4.0)
4
+ u-attributes (0.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -41,10 +41,10 @@ module Micro
41
41
  end
42
42
 
43
43
  def attributes_data(arg)
44
- normalized_arg =
45
- arg.keys.each_with_object({}) { |key, memo| memo[key.to_s] = arg[key] }
46
-
47
- yield(__attributes_data.merge(normalized_arg))
44
+ __attributes_data.merge(
45
+ Utils.hash_argument!(arg)
46
+ .each_with_object({}) { |(key, val), memo| memo[key.to_s] = val }
47
+ )
48
48
  end
49
49
  end
50
50
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Micro
4
+ module Attributes
5
+ module Utils
6
+ ARGUMENT_ERROR_MSG = 'argument must be a Hash'
7
+
8
+ def self.hash_argument!(arg)
9
+ return arg if arg.is_a?(Hash)
10
+
11
+ raise ArgumentError, ARGUMENT_ERROR_MSG
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  module Attributes
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "micro/attributes/version"
4
+ require "micro/attributes/utils"
4
5
  require "micro/attributes/macros"
5
6
 
6
7
  module Micro
@@ -16,8 +17,8 @@ module Micro
16
17
  end
17
18
 
18
19
  def base.inherited(subclass)
19
- self.attributes_data({}) do |data|
20
- data.each { |k, v| subclass.attribute(v.nil? ? k : {k => v}) }
20
+ self.attributes_data({}).each do |name, value|
21
+ subclass.attribute(value.nil? ? name : {name => value})
21
22
  end
22
23
  end
23
24
  end
@@ -49,12 +50,8 @@ module Micro
49
50
  end
50
51
 
51
52
  def attributes=(arg)
52
- raise ArgumentError, 'argument must be a Hash' unless arg.is_a?(Hash)
53
-
54
- self.class.attributes_data(arg) do |data|
55
- data.each do |name, value|
56
- instance_variable_set("@#{name}", data[name]) if attribute?(name)
57
- end
53
+ self.class.attributes_data(Utils.hash_argument!(arg)).each do |name, value|
54
+ instance_variable_set("@#{name}", value) if attribute?(name)
58
55
  end
59
56
  end
60
57
 
@@ -66,7 +63,7 @@ module Micro
66
63
  end
67
64
  end
68
65
 
69
- self.class.attributes_data(state) { |data| data }
66
+ self.class.attributes_data(state)
70
67
  end
71
68
 
72
69
  protected :attributes=
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: u-attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Serradura
@@ -58,6 +58,7 @@ files:
58
58
  - bin/setup
59
59
  - lib/micro/attributes.rb
60
60
  - lib/micro/attributes/macros.rb
61
+ - lib/micro/attributes/utils.rb
61
62
  - lib/micro/attributes/version.rb
62
63
  - lib/u-attributes.rb
63
64
  - micro-attributes.gemspec