Repository: rails/rails
File: activesupport/lib/active_support/encrypted_configuration.rb (Ruby)

Code before:
      end
    end

    delegate_missing_to :options

    def initialize(config_path:, key_path:, env_key:, raise_if_missing_key:)
      super content_path: config_path, key_path: key_path,
        env_key: env_key, raise_if_missing_key: raise_if_missing_key
      @config = nil
      @options = nil
    end

    # Find the referenced key
    # Raises +KeyError+ if not found.
    #
    # Examples:
    #
    #   require(:db_host)         # => ENV.fetch("DB_HOST")
    #   require(:database, :host) # => ENV.fetch("DATABASE__HOST")
    def require(*key)
      value = dig(*key)

      if !value.nil?
        value
      else
        raise(KeyError)
      end
    end

    # Find a upcased and double-underscored-joined string-version of the +key+ in ENV.
    # Returns nil if the key isn't found or the value of default when passed If default is
    # a block, it's called first.
    #
    # Examples:
    #
    #   config.option(:db_host)                                    # => ENV["DB_HOST"]
    #   config.option(:database, :host)                            # => ENV["DATABASE__HOST"]
    #   config.option(:database, :host, default: "missing")        # => ENV.fetch("DATABASE__HOST", "missing")
    #   config.option(:database, :host, default: -> { "missing" }) # => ENV.fetch("DATABASE__HOST", default.call)
    def option(*key, default: nil)
      value = dig(*key)

      if !value.nil?
        value
      elsif default
        default.try(:call) || default
      end
    end

    # Reload the cached values in case any of them changed or new ones were added during runtime.
    def reload

Review comment (suggestion):
Same as what `CombinedConfiguration` does:
https://github.com/rails/rails/blob/a9ee16f0b94fe53bd3b715aa4e6e3f63e69a215a/activesupport/lib/active_support/combined_configuration.rb#L28

Code after:
      end
    end

    delegate_missing_to :options

    def initialize(config_path:, key_path:, env_key:, raise_if_missing_key:)
      super content_path: config_path, key_path: key_path,
        env_key: env_key, raise_if_missing_key: raise_if_missing_key
      @config = nil
      @options = nil
    end

    # Find the referenced key
    # Raises +KeyError+ if not found.
    #
    # Examples:
    #
    #   require(:db_host)         # => ENV.fetch("DB_HOST")
    #   require(:database, :host) # => ENV.fetch("DATABASE__HOST")
    def require(*key)
      value = dig(*key)

      if !value.nil?
        value
      else
        raise KeyError, "Missing key: #{key.inspect}"
      end
    end

    # Find a upcased and double-underscored-joined string-version of the +key+ in ENV.
    # Returns nil if the key isn't found or the value of default when passed If default is
    # a block, it's called first.
    #
    # Examples:
    #
    #   config.option(:db_host)                                    # => ENV["DB_HOST"]
    #   config.option(:database, :host)                            # => ENV["DATABASE__HOST"]
    #   config.option(:database, :host, default: "missing")        # => ENV.fetch("DATABASE__HOST", "missing")
    #   config.option(:database, :host, default: -> { "missing" }) # => ENV.fetch("DATABASE__HOST", default.call)
    def option(*key, default: nil)
      value = dig(*key)

      if !value.nil?
        value
      elsif default
        default.try(:call) || default
      end
    end

    # Reload the cached values in case any of them changed or new ones were added during runtime.
    def reload