api_recipes 2.8.0 → 2.8.1

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: b8b743f62651355bb59b3d641637d8df6b28a860d5000a3b684758a7d1de5c47
4
- data.tar.gz: d2febad009985547a7a148e1b07b193d568b76bd75a2064a9c55257652ce7997
3
+ metadata.gz: c9d0a5a4530af3af22b9b22c091002d316e1bf7065c612d1d74f18f3aa62e37d
4
+ data.tar.gz: 5d322a843fa2db9cceb97cd9733b482ce17626342ad519ea036c0c821efe0d8b
5
5
  SHA512:
6
- metadata.gz: 6a4b6882211bbae0c27f546267674e501df253eb9a22303fadf0bbf85dfd26a2ada943f813ae1660164c20e3dae68d3afd61caf132e6e40be04bf1f62e9cfcd4
7
- data.tar.gz: e5429acaf4fbcaa1f5e83090d8ede9dcee36253a61b8d17b5e79fb5c4c4178115b677d91ac39e8c145af63dd1813e904834201fddbc930e45e07b3d8df3455b9
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
- unless ApiRecipes.configuration.apis_configs[api_name]
135
- ApiRecipes.configuration.apis_configs[api_name] = {}
136
- end
135
+ global_api_configs = _aprcps_global_storage[api_name]&.configs || {}
137
136
  if configs
138
- ApiRecipes.configuration.apis_configs[api_name].merge(configs) do |_, old_val, new_val|
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
- ApiRecipes.configuration.apis_configs[api_name]
145
+ global_api_configs
147
146
  end
148
147
  end
149
148
  end
@@ -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.
@@ -1,3 +1,3 @@
1
1
  module ApiRecipes
2
- VERSION = '2.8.0'.freeze
2
+ VERSION = '2.8.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Verlato