api_recipes 2.8.0 → 2.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api_recipes.rb +4 -5
- data/lib/api_recipes/utils.rb +31 -0
- data/lib/api_recipes/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: c9d0a5a4530af3af22b9b22c091002d316e1bf7065c612d1d74f18f3aa62e37d
|
4
|
+
data.tar.gz: 5d322a843fa2db9cceb97cd9733b482ce17626342ad519ea036c0c821efe0d8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ee0d8d0c2e4c52aafa513c8619f92c1ec6b5425cf06911fc48d8d18562855cd4d0aabe96bf68985323663bdb4cb461e56b353c06431e2430a3ef9d51ecd6021
|
7
|
+
data.tar.gz: 4ef8593a855dd30fd21ee97642dcc5d832f7ec34218393131d1fe6758af1dbe4a8e5ad8d76f3612d289ef6e85d02a7640a65490f6b7dc103d0e32f43fbed2409
|
data/lib/api_recipes.rb
CHANGED
@@ -117,6 +117,7 @@ module ApiRecipes
|
|
117
117
|
unless @storage
|
118
118
|
@storage = {}
|
119
119
|
end
|
120
|
+
|
120
121
|
@storage
|
121
122
|
end
|
122
123
|
|
@@ -131,11 +132,9 @@ module ApiRecipes
|
|
131
132
|
unless api_name.is_a?(String) || api_name.is_a?(Symbol)
|
132
133
|
raise ArgumentError, "no api_name provided. Given: #{api_name.inspect}"
|
133
134
|
end
|
134
|
-
|
135
|
-
ApiRecipes.configuration.apis_configs[api_name] = {}
|
136
|
-
end
|
135
|
+
global_api_configs = _aprcps_global_storage[api_name]&.configs || {}
|
137
136
|
if configs
|
138
|
-
|
137
|
+
global_api_configs.deep_merge(configs) do |_, old_val, new_val|
|
139
138
|
if new_val.nil?
|
140
139
|
old_val
|
141
140
|
else
|
@@ -143,7 +142,7 @@ module ApiRecipes
|
|
143
142
|
end
|
144
143
|
end
|
145
144
|
else
|
146
|
-
|
145
|
+
global_api_configs
|
147
146
|
end
|
148
147
|
end
|
149
148
|
end
|
data/lib/api_recipes/utils.rb
CHANGED
@@ -77,6 +77,37 @@ class Hash
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
81
|
+
#
|
82
|
+
# h1 = { a: true, b: { c: [1, 2, 3] } }
|
83
|
+
# h2 = { a: false, b: { x: [3, 4, 5] } }
|
84
|
+
#
|
85
|
+
# h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
86
|
+
#
|
87
|
+
# Like with Hash#merge in the standard library, a block can be provided
|
88
|
+
# to merge values:
|
89
|
+
#
|
90
|
+
# h1 = { a: 100, b: 200, c: { c1: 100 } }
|
91
|
+
# h2 = { b: 250, c: { c1: 200 } }
|
92
|
+
# h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
|
93
|
+
# # => { a: 100, b: 450, c: { c1: 300 } }
|
94
|
+
def deep_merge(other_hash, &block)
|
95
|
+
dup.deep_merge!(other_hash, &block)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Same as +deep_merge+, but modifies +self+.
|
99
|
+
def deep_merge!(other_hash, &block)
|
100
|
+
merge!(other_hash) do |key, this_val, other_val|
|
101
|
+
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
102
|
+
this_val.deep_merge(other_val, &block)
|
103
|
+
elsif block_given?
|
104
|
+
block.call(key, this_val, other_val)
|
105
|
+
else
|
106
|
+
other_val
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
80
111
|
# Returns a new hash with all keys converted by the block operation.
|
81
112
|
# This includes the keys from the root hash and from all
|
82
113
|
# nested hashes and arrays.
|
data/lib/api_recipes/version.rb
CHANGED