Class: SimpleParameterStore
- Inherits:
-
Object
- Object
- SimpleParameterStore
- Defined in:
- lib/simple_parameter_store.rb,
lib/simple_parameter_store/mock.rb,
lib/simple_parameter_store/version.rb
Defined Under Namespace
Modules: Mock Classes: SSMKeyError
Constant Summary collapse
- VERSION =
'0.2.1'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#decrypt ⇒ Object
readonly
Returns the value of attribute decrypt.
-
#expires_after ⇒ Object
readonly
Returns the value of attribute expires_after.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(names:, client: nil, prefix: nil, decrypt: true, expires_after: nil) ⇒ SimpleParameterStore
constructor
A new instance of SimpleParameterStore.
- #refresh ⇒ Object
- #refresh_if_needed ⇒ Object
Constructor Details
#initialize(names:, client: nil, prefix: nil, decrypt: true, expires_after: nil) ⇒ SimpleParameterStore
Returns a new instance of SimpleParameterStore.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/simple_parameter_store.rb', line 10 def initialize(names:, client: nil, prefix: nil, decrypt: true, expires_after: nil) @client = client || build_client @prefix = prefix @decrypt = decrypt @expires_after = expires_after @mappings = {} @casters = {} @cache = {} prepare(names) refresh end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
24 25 26 |
# File 'lib/simple_parameter_store.rb', line 24 def client @client end |
#decrypt ⇒ Object (readonly)
Returns the value of attribute decrypt.
24 25 26 |
# File 'lib/simple_parameter_store.rb', line 24 def decrypt @decrypt end |
#expires_after ⇒ Object (readonly)
Returns the value of attribute expires_after.
24 25 26 |
# File 'lib/simple_parameter_store.rb', line 24 def expires_after @expires_after end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
24 25 26 |
# File 'lib/simple_parameter_store.rb', line 24 def expires_at @expires_at end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
24 25 26 |
# File 'lib/simple_parameter_store.rb', line 24 def prefix @prefix end |
Instance Method Details
#[](key) ⇒ Object
45 46 47 48 |
# File 'lib/simple_parameter_store.rb', line 45 def [](key) refresh_if_needed @cache.fetch(key) end |
#expired? ⇒ Boolean
41 42 43 |
# File 'lib/simple_parameter_store.rb', line 41 def expired? expires_after && expires_at < Time.now end |
#refresh ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/simple_parameter_store.rb', line 26 def refresh fetch.each_pair do |name, value| key, = @mappings.rassoc(name) caster = @casters.fetch(key) value = caster.call(value) @cache[key] = value end @expires_at = Time.now + expires_after if expires_after end |
#refresh_if_needed ⇒ Object
37 38 39 |
# File 'lib/simple_parameter_store.rb', line 37 def refresh_if_needed refresh if expired? end |