chambermaid 0.1.0 → 0.2.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: 96de691a190b68ff6d24e2410f1191ac0f3ef29c534de37ae73b7e7a7f4d8530
4
- data.tar.gz: 16b2fb406a93c823bba30938594294fdcad94a1588718327c57b1d10fddf7f0a
3
+ metadata.gz: ceb4e76a467a39e91b32a40efff57e8fe8d213e28ea38c9742569af98eac7e0f
4
+ data.tar.gz: dfdb963dece1c57711fae828eaeebf53490ce2569f6fa339839d2c01a24787ca
5
5
  SHA512:
6
- metadata.gz: 4d73421e3cdac6a8e835b745df14a2fe012f4785183e4cc28c4222358553a8ac29a12f5e7cd256af7d7bf2bfcbf5bf8cf2783d089dbb09e435d07f717a359269
7
- data.tar.gz: 7d7a11dbb825742c23bd9a1d8b2ac10cabb44c92b66d6fea40ae828c01862611d97b5422efafd3f57f9c5826e39648240eb389f69d9d98acf0635118908c266a
6
+ metadata.gz: 2997b5bf940b31802cb900d50b042820885da4209fff8e2231228994fbb3daf3efa4c979fb6a41f37a1512e3cea96440e3744b8ca2939dcd2543cc1287c1e960
7
+ data.tar.gz: cc518b62b452ea0c63e83b04fd3535345ed335a671fffd6fba6c184addfdaa45a9f29553a825d55e97921598300675e1c054d496dd30a850ca520968170f15be
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chambermaid (0.1.0)
4
+ chambermaid (0.2.0)
5
5
  aws-sdk-ssm (~> 1.85)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -36,12 +36,18 @@ Chambermaid.add_namespace("/my/param/namespace")
36
36
  Chambermaid.configure do |config|
37
37
  config.add_namespace("/my/param/namespace")
38
38
 
39
- # Set `overwrite_duplicates: true` to choose these params over existing
39
+ # Set `overload: true` to choose these params over existing
40
40
  # ones in ENV when they are merged together
41
- config.add_namespace("/my/important/namespace", overwrite_duplicates: true)
41
+ config.add_namespace("/my/important/namespace", overload: true)
42
42
  end
43
43
  ```
44
44
 
45
+ **Restore ENV to original state**
46
+ ```ruby
47
+ Chambermaid.restore!
48
+ Chambermaid.reset! # alias of .restore!
49
+ ```
50
+
45
51
  ## Development
46
52
 
47
53
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -2,6 +2,11 @@ require "chambermaid/parameter_store"
2
2
 
3
3
  module Chambermaid
4
4
  module Base
5
+ def self.extended(base)
6
+ # Make a copy of ENV before we mess it all up
7
+ @@_original_env = ENV.to_h.dup
8
+ end
9
+
5
10
  extend self
6
11
 
7
12
  def configure
@@ -15,35 +20,47 @@ module Chambermaid
15
20
 
16
21
  # @todo
17
22
  def reload!
23
+ restore!
24
+ @namespaces.each do |ns|
25
+ ns[:store].reload!
26
+ update_env!(
27
+ params: ns[:store].params,
28
+ overload: ns[:overload]
29
+ )
30
+ end
18
31
  end
19
32
 
33
+ # Restore ENV to its original state
34
+ def restore!
35
+ ENV.replace(@@_original_env)
36
+ end
37
+ alias :reset! :restore!
38
+
20
39
  # Add an AWS SSM parameter namespace to ENV
21
40
  #
22
41
  # @param [String] path
23
- # @param [Boolean] overwrite_duplicates
42
+ # @param [Boolean] overload
24
43
  # true - replace any duplicate ENV keys with new params
25
44
  # false - keep any existing duplicate ENV key values
26
45
  #
27
46
  # @raise
28
- def add_namespace(path, overwrite_duplicates: false)
29
- @namespaces ||= {}
30
- raise "namespace already included in ENV" unless @namespaces[path].nil?
31
-
32
- @namespaces[path] = ParameterStore.load!(path: path)
33
- update_env!(
34
- params: @namespaces[path].params,
35
- overwrite_duplicates: overwrite_duplicates
36
- )
47
+ def add_namespace(path, overload: false)
48
+ @namespaces ||= []
49
+ # raise "namespace already included in ENV" unless @namespaces[path].nil?
50
+
51
+ store = ParameterStore.load!(path: path)
52
+ @namespaces << { store: store, overload: overload }
53
+ update_env!(params: store.params, overload: overload)
37
54
  end
38
55
 
39
56
  # Inject into ENV
40
57
  #
41
58
  # @param [Hash] params
42
- # @param [Boolean] overwrite_duplicates
59
+ # @param [Boolean] overload
43
60
  # true - replace any duplicate ENV keys with new params
44
61
  # false - keep any existing duplicate ENV key values
45
- def update_env!(params:, overwrite_duplicates:)
46
- if overwrite_duplicates
62
+ def update_env!(params:, overload:)
63
+ if overload
47
64
  ENV.update(params)
48
65
  else
49
66
  current_env = ENV.to_h.dup
@@ -10,6 +10,11 @@ module Chambermaid
10
10
  fetch_ssm_params!
11
11
  end
12
12
 
13
+ def reload!
14
+ clear_params!
15
+ fetch_ssm_params!
16
+ end
17
+
13
18
  def self.load!(path:)
14
19
  store = new(path: path)
15
20
  store.load!
@@ -55,5 +60,10 @@ module Chambermaid
55
60
  next_token: next_token
56
61
  )
57
62
  end
63
+
64
+ def clear_params!
65
+ @params = nil
66
+ @params_list = nil
67
+ end
58
68
  end
59
69
  end
@@ -1,3 +1,3 @@
1
1
  module Chambermaid
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chambermaid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Zimmerman