finest-builder 1.1.2 → 2.0.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: 1ac8be2e6998bd2599cb0e89a25c0716b1c3891d90b077acd56079eb702d66a1
4
- data.tar.gz: 67cf57d634ea3edda51266744019bb82d68cbf2aaa988c49ab50911d70a3bad1
3
+ metadata.gz: 66c7b96883a0a0dfec0738a446e283eda837a06585d04309c07badf3425b0d96
4
+ data.tar.gz: 2ba3a8157b0ec1e4e42e5f9f77810cab68dfc5f91a5ab6d6689cdf330ebe3d1b
5
5
  SHA512:
6
- metadata.gz: b075bae8a917b4a26f961f9d07ac819d273f8fb67483b87d68b3676c2b75e2c1a1bccf340724d37b47b9e38372b27896d4d190894b317621610fb89d05f62719
7
- data.tar.gz: d8446bbc192a8b192f6cfd00cd9c83628773f595242b5aedf48cda5e580345ab9474eac255172daf0f5ae89aab9993ee2ec834593de48123dfdeaa28ac8f1110
6
+ metadata.gz: fe4a9c7f0f9cdac5d70dd4ab0c0f31fb71b1efffd3171b3279a1fc184e5cd42d1ebbf5432740a7b5de76ad35406de5b3acd9ef337c0e9dc45ac5106a0f921e1d
7
+ data.tar.gz: 8c306f2dce9adda3937b47f8f43b0f60cdff083cce5b04163cb4ecab88d83e3ce4d30779b7b16ab44a7e5dd83f594136c37ce9139e4c44f43951d4b75afb96bb
data/.travis.yml CHANGED
@@ -2,5 +2,5 @@
2
2
  language: ruby
3
3
  cache: bundler
4
4
  rvm:
5
- - 2.7.4
6
- before_install: gem install bundler -v 2.1.4
5
+ - 3.1.2
6
+ before_install: gem install bundler -v 2.2.24
@@ -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('>= 2.7.4')
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
 
@@ -1,5 +1,5 @@
1
1
  module Finest
2
2
  module Builder
3
- VERSION = "1.1.2"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -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
- # obj[key].is_a?(Hash) ? self.class.new(obj[key]) : obj[key]
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
- # If it's not a Hash will check if it's a Array instead,
62
- # checking out whether it responds to a Array.each method or not.
63
- # elsif obj.respond_to?(:each)
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) ? self.class.new(obj[key]) : obj[key]
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|
@@ -109,7 +123,7 @@ module Finest
109
123
  if attribute =~ /=$/
110
124
  @to_h[attribute.chop] =
111
125
  if args[0].respond_to?(:key?) || args[0].is_a?(Hash)
112
- self.class.new(args[0])
126
+ self.class.new(json: args[0])
113
127
  else
114
128
  args[0]
115
129
  end
@@ -124,10 +138,12 @@ module Finest
124
138
 
125
139
  # Finest Builder
126
140
  module Builder
141
+ include Helper
142
+
127
143
  class Error < StandardError; end
128
144
 
129
- include Helper
130
145
  alias initialize build_by_keys
146
+
131
147
  end
132
148
 
133
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: 1.1.2
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: 2022-03-25 00:00:00.000000000 Z
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: 2.7.4
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.1.6
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