finest-builder 1.1.1 → 2.0.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/.travis.yml +2 -2
- data/finest-builder.gemspec +1 -1
- data/lib/finest/builder/version.rb +1 -1
- data/lib/finest/builder.rb +29 -11
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66c7b96883a0a0dfec0738a446e283eda837a06585d04309c07badf3425b0d96
|
4
|
+
data.tar.gz: 2ba3a8157b0ec1e4e42e5f9f77810cab68dfc5f91a5ab6d6689cdf330ebe3d1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe4a9c7f0f9cdac5d70dd4ab0c0f31fb71b1efffd3171b3279a1fc184e5cd42d1ebbf5432740a7b5de76ad35406de5b3acd9ef337c0e9dc45ac5106a0f921e1d
|
7
|
+
data.tar.gz: 8c306f2dce9adda3937b47f8f43b0f60cdff083cce5b04163cb4ecab88d83e3ce4d30779b7b16ab44a7e5dd83f594136c37ce9139e4c44f43951d4b75afb96bb
|
data/.travis.yml
CHANGED
data/finest-builder.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
#spec.description = %q{TODO: Write a longer description or delete this line.}
|
13
13
|
spec.homepage = 'https://github.com/eddygarcas/finest-builder'
|
14
14
|
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new('>=
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 3.1.2')
|
16
16
|
|
17
17
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
|
18
18
|
|
data/lib/finest/builder.rb
CHANGED
@@ -30,6 +30,7 @@ module Finest
|
|
30
30
|
# e.client.id
|
31
31
|
#
|
32
32
|
def build_by_keys(json = {}, keys = [])
|
33
|
+
|
33
34
|
keys = keys.empty? ? json.keys : keys
|
34
35
|
raise ArgumentError unless keys&.respond_to?(:each)
|
35
36
|
|
@@ -56,18 +57,31 @@ module Finest
|
|
56
57
|
#
|
57
58
|
# If result object is a hash itself, will call constructor method to parse this hash first.
|
58
59
|
#
|
59
|
-
#
|
60
|
+
# if obj[key].is_a?(Hash)
|
61
|
+
# self.class.new(obj[key])
|
62
|
+
#
|
63
|
+
# If it's an array, will call the constructor method for each element of the array, mapping the result.
|
64
|
+
#
|
65
|
+
# elsif (obj[key].is_a?(Array))
|
60
66
|
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
67
|
+
# As mentioned before, this methods looks for the key passed as parameter, if it's not found, will
|
68
|
+
# go through the nested hash looking for the key, calling itself recursively.
|
69
|
+
#
|
70
|
+
# This way we can look for specific keys inside a complex hash structure and ignore the rest.
|
71
|
+
# The result of this action will be an object with the keys found and their values.
|
72
|
+
# If eventually the keys was not found, it will assign nil to the instance variable.
|
64
73
|
#
|
65
|
-
# For every Array found it make a recursive call to itself passing
|
66
|
-
# the last element of the array and the Key it's looking for.
|
67
|
-
# r = nested_hash_value(a.last, key)
|
68
74
|
def nested_hash_value(obj, key)
|
69
75
|
if obj.respond_to?(:key?) && obj.key?(key)
|
70
|
-
obj[key].is_a?(Hash)
|
76
|
+
if obj[key].is_a?(Hash)
|
77
|
+
self.class.new(obj[key])
|
78
|
+
elsif (obj[key].is_a?(Array))
|
79
|
+
obj[key].map! do |a|
|
80
|
+
a.respond_to?(:key?) ? self.class.new(a) : a
|
81
|
+
end
|
82
|
+
else
|
83
|
+
obj[key]
|
84
|
+
end
|
71
85
|
elsif obj.respond_to?(:each)
|
72
86
|
r = nil
|
73
87
|
obj.find do |*a|
|
@@ -81,7 +95,9 @@ module Finest
|
|
81
95
|
accessor_builder(name.to_s.gsub(/=$/, ''), args[0]) if name.to_s =~ /=$/
|
82
96
|
end
|
83
97
|
|
84
|
-
def respond_to_missing
|
98
|
+
def respond_to_missing?(method_name, include_private = false)
|
99
|
+
method_name.to_s.start_with?('to_') || super
|
100
|
+
end
|
85
101
|
|
86
102
|
def attribute_from_inner_key(elem, attr, in_key = nil)
|
87
103
|
{ attr.to_sym => nested_hash_value(elem, in_key&.present? ? in_key : attr.to_s) }
|
@@ -107,7 +123,7 @@ module Finest
|
|
107
123
|
if attribute =~ /=$/
|
108
124
|
@to_h[attribute.chop] =
|
109
125
|
if args[0].respond_to?(:key?) || args[0].is_a?(Hash)
|
110
|
-
self.class.new(args[0])
|
126
|
+
self.class.new(json: args[0])
|
111
127
|
else
|
112
128
|
args[0]
|
113
129
|
end
|
@@ -122,10 +138,12 @@ module Finest
|
|
122
138
|
|
123
139
|
# Finest Builder
|
124
140
|
module Builder
|
141
|
+
include Helper
|
142
|
+
|
125
143
|
class Error < StandardError; end
|
126
144
|
|
127
|
-
include Helper
|
128
145
|
alias initialize build_by_keys
|
146
|
+
|
129
147
|
end
|
130
148
|
|
131
149
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: finest-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduard Garcia Castello
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -46,14 +46,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: 3.1.2
|
50
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
|
-
rubygems_version: 3.
|
56
|
+
rubygems_version: 3.3.7
|
57
57
|
signing_key:
|
58
58
|
specification_version: 4
|
59
59
|
summary: Builder modules to create either class ghost methods from a given JSON or
|