binky-builder 0.5.1 → 0.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e46f9b7c4de7db6f057e4cfd4b95003477e0bb38690b0afd8ad1225cdb74c4f
4
- data.tar.gz: e60a47865a0808cbd95bd3e88061e7cf85f9714f160021b4f12fee63ec65c6ff
3
+ metadata.gz: fe99fd93ec07d283c7943a29aa9173271689daf1683b1a7a4e863b01142e3a3b
4
+ data.tar.gz: 34545763117bfdc5f0d0efde8aa6760be2b29f0968bd6e1368442093684e1417
5
5
  SHA512:
6
- metadata.gz: 226453a1025082447e2acf396845e44c03bead9a8cf1d8c5c94d64a8c42cbea3543889786b53b30864858de6c7379a6a87d548e1960844886f296d977360a5eb
7
- data.tar.gz: b43b8bc0858299c65f247914aa39808647b6046ab7c03d13cbb0f2c8d1463cf58e119037d00c86eb7bfd3d9319a4e787552a09166dd218f7b409f8f17b3c3711
6
+ metadata.gz: 04c865d81ec3920b4dc46052259338e5ac55207ec03b3da45d6b5d5feb28c8ab00a5b192a91f5e7665dd45b444fa8b5c3f09c694c8ed3b3fe23f93acd82001bd
7
+ data.tar.gz: 2c68c2d9aeeb59554f39e5c08690b41d34ae504b51c119ca38d731b627e121b06881e01ef9c4423361934454effc4eed8fea88cecb205cf5f64b07af358a9200
@@ -7,14 +7,15 @@ module Binky
7
7
  # Keys are given through a block.
8
8
  # The result of it it's stored on a instance variable called to_hash and accessible through accessors with same name.
9
9
  def build_by_keys(json = {}, keys = nil)
10
- accessor_builder('to_h',{})
11
10
  k = keys || json&.keys
12
- raise ArgumentError unless k&.respond_to?(:each)
11
+ raise ArgumentError "keys argument is not an array" unless k&.respond_to?(:each)
12
+ accessor_builder('to_h',{})
13
13
  json.transform_keys!(&:to_s)
14
- k.each do |key|
14
+ k&.reject!{|ky| ky.end_with?('=')}
15
+ k&.each do |key|
15
16
  self.send("#{key}=",nested_hash_value(json, key.to_s))
16
17
  @to_h.merge!({key.to_sym => nested_hash_value(json,key.to_s)})
17
- end unless json.nil?
18
+ end
18
19
  yield self if block_given?
19
20
  self
20
21
  end
@@ -43,7 +44,6 @@ module Binky
43
44
  obj[key]
44
45
  elsif obj.respond_to?(:each)
45
46
  r = nil
46
- #The asterisk "splat" operator means you can pass multiple parameters in its place and the block will see them as an array.
47
47
  obj.find do |*a|
48
48
  r = nested_hash_value(a.last, key)
49
49
  end
@@ -55,8 +55,8 @@ module Binky
55
55
  accessor_builder name.to_s.chop, args[0]
56
56
  end
57
57
 
58
- def attribute_from_inner_key(element, attribute, inner_key = nil)
59
- {attribute.to_sym => nested_hash_value(element, inner_key&.present? ? inner_key : attribute.to_s)}
58
+ def attribute_from_inner_key(elem, attr, in_key = nil)
59
+ {attr.to_sym => nested_hash_value(elem, in_key&.present? ? in_key : attr.to_s)}
60
60
  end
61
61
  end
62
62
 
@@ -88,14 +88,7 @@ module Binky
88
88
  module Builder
89
89
  class Error < StandardError; end
90
90
  include Helper
91
-
92
- def initialize(json = {}, keys = nil)
93
- k = keys || json&.keys
94
- k&.reject! {|key| key.to_s.include?("=")}
95
- json.transform_keys!(&:to_s)
96
- k&.each do |key|
97
- self.send("#{key}=",nested_hash_value(json, key.to_s))
98
- end unless json.nil?
99
- end
91
+ alias_method :initialize,:build_by_keys
100
92
  end
93
+
101
94
  end
@@ -1,5 +1,5 @@
1
1
  module Binky
2
2
  module Builder
3
- VERSION = "0.5.1"
3
+ VERSION = "0.5.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binky-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduard Garcia Castello