simplygenius-atmos 0.12.0 → 0.12.1

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: a43cd732a3f97e0fc2884f1b284b8f389db9b1845879a1e8cd5b23a657b9dab6
4
- data.tar.gz: 0b84e5d5026b849bac355875bc4759b8cfc21abc4ad51627d2e35626f928f2e4
3
+ metadata.gz: 184052156c0ecd551e93ad3a1cc212bc2132f5b77409348f1c0cedcb4740b353
4
+ data.tar.gz: 67b48fb4bb4f84a922ac2879bcd38273c552fa213983f2f2d461669f6eb06587
5
5
  SHA512:
6
- metadata.gz: 84bfe472a2bef731c2cd3dc715ca2b0d214a343cef6491f09bc4762445d7faf340b704366a5b0e099c3e9a42cb6f4e23fecf918671cdeb6a51b4a1a7e15a993e
7
- data.tar.gz: 2a3f7167cd23068e9e8ea810810ed3e896b36d6c803b8f844b38bfa11e8127dd37505fcf91995321d9a53af4d851236eebebfc8d6421a6c03109aa8e90267596
6
+ metadata.gz: 3f3a38df1a9759746af1999bd3e8e0fe542ddb89092a557b81720f470e7e12b3ea13eb814aa64b36f906a7534a0a96537c421bdd707cd45513e363a2c8bf8388
7
+ data.tar.gz: e68a88d3b25b8f307fec0ada80eb5f6eb9f97fdb6da550dec70db58483001b769e86873410d0328677f53ee32e9f910b0521b55a1f0ccf327668af6ad22f7546
@@ -1,3 +1,8 @@
1
+ 0.12.1 (10/14/2020)
2
+ -------------------
3
+
4
+ * fix bug with deeply nested overrides [60cb84a](https://github.com/simplygenius/atmos/commit/60cb84a)
5
+
1
6
  0.12.0 (10/12/2020)
2
7
  -------------------
3
8
 
@@ -114,13 +114,14 @@ module SimplyGenius
114
114
 
115
115
  if merge_to_existing
116
116
  existing = load_file(user_config_file, SettingsHash.new)
117
- data = config_merge(existing, data, ["saving #{user_config_file}"], finalize: true)
117
+ data = config_merge(existing, data, ["saving #{user_config_file}"])
118
+ data = finalize_merge(data)
118
119
  end
119
120
  File.write(user_config_file, YAML.dump(data.to_hash))
120
121
  File.chmod(0600, user_config_file)
121
122
  end
122
123
 
123
- def config_merge(lhs, rhs, debug_state=[], finalize: true)
124
+ def config_merge(lhs, rhs, debug_state=[])
124
125
  result = nil
125
126
 
126
127
  return rhs if lhs.nil?
@@ -136,30 +137,22 @@ module SimplyGenius
136
137
  rhs.each do |k, v|
137
138
  new_state = debug_state + [k]
138
139
 
140
+ # The load sequence could have multiple overrides and its not
141
+ # obvious to the user which are lhs vs rhs, so rather than having
142
+ # one seem to win arbitrarily, we collect them all additively
143
+ # under their key, then at the end of the load process we push the
144
+ # override back as a replacement for its base key in the
145
+ # finalize_merge method. This means that if one has multiple
146
+ # overrides for the same key (not usually what one wants), those
147
+ # overrides get merged together additively before replacing the
148
+ # base. Thus the need for the log messages below.
149
+ #
139
150
  if k =~ /^\^/
140
151
  logger.debug { "Override seen at #{new_state.join(" -> ")}" }
141
152
  logger.warn { "Multiple overrides on a single key seen at #{new_state.join(" -> ")}" } if result.has_key?(k)
142
153
  end
143
154
 
144
- result[k] = config_merge(result[k], v, new_state, finalize: finalize)
145
- end
146
-
147
- # The load sequence could have multiple overrides and its not
148
- # obvious to the user which are lhs vs rhs, so rather than having
149
- # one seem to win arbitrarily, we collect them all additively under
150
- # their key, then at the end of the load process we push the
151
- # override back as a replacement for its base key.
152
- # This means that if one has multiple overrides for the same key
153
- # (not usually what one wants), those overrides get merged together
154
- # additively before replacing the base. Thus the need for the debug
155
- # log message above.
156
- if finalize
157
- result.each do |k, v|
158
- if k =~ /^\^(.*)/
159
- key = k.is_a?(Symbol) ? $1.to_sym : $1
160
- result[key] = result.delete(k)
161
- end
162
- end
155
+ result[k] = config_merge(result[k], v, new_state)
163
156
  end
164
157
 
165
158
  when Enumerable
@@ -183,6 +176,27 @@ module SimplyGenius
183
176
 
184
177
  private
185
178
 
179
+ def finalize_merge(config)
180
+ result = config.deep_dup
181
+
182
+ config.each do |k, v|
183
+
184
+ key = k
185
+
186
+ if k =~ /^\^(.*)/
187
+ key = k.is_a?(Symbol) ? $1.to_sym : $1
188
+ result[key] = result.delete(k)
189
+ end
190
+
191
+ if v.is_a?(Hash)
192
+ result[key] = finalize_merge(v)
193
+ end
194
+
195
+ end
196
+
197
+ return result
198
+ end
199
+
186
200
  def load_remote_config_sources(config, *remote_sources)
187
201
  remote_sources.each do |remote_source|
188
202
  logger.debug("Loading remote atmos config file: #{remote_source}")
@@ -222,7 +236,7 @@ module SimplyGenius
222
236
 
223
237
  begin
224
238
  submap = config.deep_fetch(group, name)
225
- config = config_merge(config, submap, ["#{submap_file} submap(#{group}.#{name})"], finalize: false)
239
+ config = config_merge(config, submap, ["#{submap_file} submap(#{group}.#{name})"])
226
240
  rescue
227
241
  logger.debug("No #{group} config found for '#{name}'")
228
242
  end
@@ -245,7 +259,7 @@ module SimplyGenius
245
259
  @user_config_file = @full_config.notation_get("atmos.user_config") || @user_config_file
246
260
  @user_config_file = File.expand_path(@user_config_file)
247
261
  user_config_file_data = load_file(@user_config_file)
248
- temp_settings = create_settings(config_merge(@full_config, user_config_file_data, [@user_config_file], finalize: false), finalize: false)
262
+ temp_settings = create_settings(config_merge(@full_config, user_config_file_data, [@user_config_file]), finalize: true)
249
263
 
250
264
  @full_config = load_config_sources(File.dirname(config_file), @full_config, *Array(temp_settings.notation_get("atmos.config_sources")))
251
265
  @full_config = load_remote_config_sources(@full_config, *Array(temp_settings.notation_get("atmos.remote_config_sources")))
@@ -255,7 +269,7 @@ module SimplyGenius
255
269
  @full_config = load_submap(File.dirname(config_file), 'providers', provider_name, @full_config)
256
270
  @full_config = load_submap(File.dirname(config_file), 'environments', atmos_env, @full_config)
257
271
 
258
- @full_config = config_merge(@full_config, user_config_file_data, [@user_config_file], finalize: false)
272
+ @full_config = config_merge(@full_config, user_config_file_data, [@user_config_file])
259
273
 
260
274
  conf = create_settings(@full_config, finalize: true)
261
275
 
@@ -288,7 +302,7 @@ module SimplyGenius
288
302
  data = SettingsHash.new(data)
289
303
  data = block.call(data) if block
290
304
  # if lhs has a override ^, then it loses it when rhs gets merged in, which breaks things for subsequent merges
291
- config = config_merge(config, data, [location], finalize: false)
305
+ config = config_merge(config, data, [location])
292
306
  @included_configs[location] = yml_string
293
307
  end
294
308
 
@@ -303,7 +317,8 @@ module SimplyGenius
303
317
  }
304
318
 
305
319
  global = SettingsHash.new(config.reject {|k, v| ['providers', 'environments'].include?(k) })
306
- conf = config_merge(global, builtins, ["builtins"], finalize: finalize)
320
+ conf = config_merge(global, builtins, ["builtins"])
321
+ conf = finalize_merge(conf) if finalize
307
322
 
308
323
  conf.error_resolver = ->(statement) { find_config_error(statement) }
309
324
  conf.enable_expansion = true
@@ -1,5 +1,5 @@
1
1
  module SimplyGenius
2
2
  module Atmos
3
- VERSION = "0.12.0"
3
+ VERSION = "0.12.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplygenius-atmos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Conway
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-13 00:00:00.000000000 Z
11
+ date: 2020-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler