instance method
option
Ruby on Rails edge
Since edgeSignature
option(*key, default: nil)
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) “`
Parameters
-
keyrest -
defaultkey = nil
Source
# File activesupport/lib/active_support/combined_configuration.rb, line 79
def option(*key, default: nil)
@configurations.each do |config|
value = config.option(*key)
return value unless value.nil?
end
default.respond_to?(:call) ? default.call : default
end
Defined in activesupport/lib/active_support/combined_configuration.rb line 79
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::CombinedConfiguration