instance method
option
Ruby on Rails edge
Since edgeSignature
option(*key, default: nil)
Find an upcased and double-underscored-joined string-version of the key in ENV. 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.
Given ENV:
DB_HOST: "env.example.com"
DATABASE__HOST: "env.example.com"
Examples:
option(:db_host) # => "env.example.com"
option(:missing) # => nil
option(:missing, default: "localhost") # => "localhost"
option(:missing, default: -> { "localhost" }) # => "localhost"
Parameters
-
keyrest -
defaultkey = nil
Source
# File activesupport/lib/active_support/env_configuration.rb, line 65
def option(*key, default: nil)
if default.respond_to?(:call)
@envs.fetch(envify(*key)) { default.call }
else
@envs.fetch envify(*key), default
end
end
Defined in activesupport/lib/active_support/env_configuration.rb line 65
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::EnvConfiguration