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 +4 -4
- data/lib/binky/builder.rb +9 -16
- data/lib/binky/builder/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe99fd93ec07d283c7943a29aa9173271689daf1683b1a7a4e863b01142e3a3b
|
4
|
+
data.tar.gz: 34545763117bfdc5f0d0efde8aa6760be2b29f0968bd6e1368442093684e1417
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04c865d81ec3920b4dc46052259338e5ac55207ec03b3da45d6b5d5feb28c8ab00a5b192a91f5e7665dd45b444fa8b5c3f09c694c8ed3b3fe23f93acd82001bd
|
7
|
+
data.tar.gz: 2c68c2d9aeeb59554f39e5c08690b41d34ae504b51c119ca38d731b627e121b06881e01ef9c4423361934454effc4eed8fea88cecb205cf5f64b07af358a9200
|
data/lib/binky/builder.rb
CHANGED
@@ -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
|
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
|
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(
|
59
|
-
{
|
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
|