Module: Collavre::IntegrationSettings
- Defined in:
- lib/collavre/integration_settings.rb,
lib/collavre/integration_settings/registry.rb,
lib/collavre/integration_settings/resolver.rb,
lib/collavre/integration_settings/key_definition.rb
Defined Under Namespace
Classes: KeyDefinition, Registry, Resolver
Class Method Summary collapse
-
.fetch(key, default: nil, boot_safe: false) ⇒ Object
Resolve a registered key with a safety net for boot-time consumers.
Class Method Details
.fetch(key, default: nil, boot_safe: false) ⇒ Object
Resolve a registered key with a safety net for boot-time consumers. Returns ‘Resolver.get(key)` when the registry+DB are reachable, otherwise falls back to `ENV`. After the next boot, the DB value wins —matching the `requires_restart` semantics callers register.
‘boot_safe: true` additionally rescues `ActiveRecord::Encryption::Errors::Base` so callers reached before `config/initializers/active_record_encryption.rb` runs (e.g. `storage.yml`, `config/environments/*.rb`) cannot crash the boot if an encrypted row is unreadable. Runtime callers MUST leave this false so decryption failures surface instead of silently treating values as blank.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/collavre/integration_settings.rb', line 24 def self.fetch(key, default: nil, boot_safe: false) return ENV[key.to_s.upcase].presence || default unless defined?(Resolver) value = begin Resolver.get(key) rescue Resolver::UnknownKeyError nil rescue ActiveRecord::StatementInvalid, ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished, NameError ENV[key.to_s.upcase] rescue StandardError => e raise unless boot_safe && defined?(ActiveRecord::Encryption::Errors::Base) && e.is_a?(ActiveRecord::Encryption::Errors::Base) ENV[key.to_s.upcase] end value.presence || default end |