Class: Collavre::IntegrationSettings::Resolver
- Inherits:
-
Object
- Object
- Collavre::IntegrationSettings::Resolver
- Defined in:
- lib/collavre/integration_settings/resolver.rb
Overview
Resolves the live value for a registered integration setting key.
Precedence: **DB > ENV > registered default.**
-
DB value wins as long as an ‘::Collavre::IntegrationSetting` row exists with a non-blank value (encrypted at rest via `::Collavre::IntegrationSetting`).
-
ENV is consulted only when no DB row exists.
-
The registry’s static default is the final fallback.
Caching:
-
Sensitive definitions are NEVER cached. ‘Rails.cache` may resolve to a durable store (e.g. `:solid_cache_store` in production), which would persist decrypted secrets outside the encrypted `value` column and defeat at-rest encryption. Sensitive reads hit the DB every time.
-
Non-sensitive definitions are memoized in ‘Rails.cache` for 5 minutes under `::Collavre::IntegrationSetting.cache_key_for(key)`. The model’s ‘after_commit` hook invalidates this key on any write.
Defined Under Namespace
Classes: UnknownKeyError
Constant Summary collapse
- CACHE_TTL =
5.minutes
Class Method Summary collapse
-
.get(key) ⇒ String?
Resolve the current value for a registered key.
-
.source_for(key) ⇒ Symbol
Report which source currently provides the value for a key.
Class Method Details
.get(key) ⇒ String?
Resolve the current value for a registered key.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/collavre/integration_settings/resolver.rb', line 33 def get(key) definition = Registry.instance.find(key) or raise UnknownKeyError, "Unknown integration setting: #{key}" return resolve(definition) if definition.sensitive Rails.cache.fetch(::Collavre::IntegrationSetting.cache_key_for(definition.key), expires_in: CACHE_TTL) do resolve(definition) end end |
.source_for(key) ⇒ Symbol
Report which source currently provides the value for a key.
48 49 50 51 52 53 |
# File 'lib/collavre/integration_settings/resolver.rb', line 48 def source_for(key) definition = Registry.instance.find(key) or return :unknown return :db if ::Collavre::IntegrationSetting.find_by(key: definition.key)&.value.present? return :env if ENV[definition.env_var].present? :default end |