Allows for configuration keys to be pulled from multiple backends. Keys are pulled in first-found order from the configuration backends that the combined configuration has been initialized with.
This is used by Rails to offer a unified API for fetching credentials from both ENV and the encrypted file. You can access this through Rails.app.creds within a Rails application.
Class Public methods
new(*configurations) Link
Instance Public methods
keys() Link
Returns a unique array of all symbolized keys available across all backend configurations.
Examples of Rails-configured access:
ENV["DB_HOST"] = "localhost" Rails.app.credentials # has keys [:secret_key_base, :aws] Rails.app.creds.keys # => [:db_host, :secret_key_base, :aws]
option(*key, default: nil) Link
Find singular or nested keys across all backends. Returns nil if no backend holds the key. If a default value is defined, it (or its callable value) will be returned on a missing key or nil value.
Given ENV:
DATABASE__HOST: "env.example.com"
And credentials:
database: host: "creds.example.com" api_key: "secret" api_host: null
Examples:
option(:database, :host) # => "env.example.com" (ENV overrides credentials) option(:missing) # => nil option(:missing, default: "localhost") # => "localhost" option(:missing, default: -> { "localhost" }) # => "localhost" option(:api_host, default: "api.example.com") # => "api.example.com" (nil values use default)
reload() Link
Reload the cached values for all of the backend configurations.
require(*key) Link
Find singular or nested keys across all backends. Raises KeyError if no backend holds the key or if the value is nil.
Given ENV:
DATABASE__HOST: "env.example.com"
And credentials:
database: host: "creds.example.com" api_key: "secret" api_host: null
Examples:
require(:database, :host) # => "env.example.com" (ENV overrides credentials) require(:api_key) # => "secret" (from credentials) require(:missing) # => KeyError require(:api_host) # => KeyError (nil values are treated as missing)