instance method
option
Ruby on Rails edge
Since edgeSignature
option(*key, default: nil)
Find singular or nested keys. Returns nil if the key isn’t found. If a default value is defined, it (or its callable value) will be returned on a missing key or nil value.
Given configuration:
“‘ db_port: null database:
host: "db.example.com"
“‘
Examples:
“‘ option(:database, :host) # => “db.example.com” option(:missing) # => nil option(:missing, default: “localhost”) # => “localhost” option(:missing, default: -> { “localhost” }) # => “localhost” option(:db_port, default: 5432) # => 5432 (nil values use default) “`
Parameters
-
keyrest -
defaultkey = nil
Source
# File activesupport/lib/active_support/encrypted_configuration.rb, line 113
def option(*key, default: nil)
value = dig(*key)
if !value.nil?
value
elsif default.respond_to?(:call)
default.call
else
default
end
end
Defined in activesupport/lib/active_support/encrypted_configuration.rb line 113
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::EncryptedConfiguration