instance method option

Ruby on Rails edge

Since edge

Signature

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

key rest
default key = nil
Source
# File activesupport/lib/active_support/combined_configuration.rb, line 80
    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 80 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::CombinedConfiguration

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close