Method: Hanami::Controller::Configuration#default_request_format

Defined in:
lib/hanami/controller/configuration.rb

#default_request_format(format) ⇒ Object #default_request_formatSymbol?

Set a format as default fallback for all the requests without a strict requirement for the mime type.

The given format must be coercible to a symbol, and be a valid mime type alias. If it isn’t, at the runtime the framework will raise a Hanami::Controller::UnknownFormatError.

By default this value is nil.

This is part of a DSL, for this reason when this method is called with an argument, it will set the corresponding instance variable. When called without, it will return the already set value, or the default.

Examples:

Getting the value

require 'hanami/controller'

Hanami::Controller.configuration.default_request_format # => nil

Setting the value

require 'hanami/controller'

Hanami::Controller.configure do
  default_request_format :html
end

Overloads:

  • #default_request_format(format) ⇒ Object

    Sets the given value

    Parameters:

    • format (#to_sym)

      the symbol format

    Raises:

    • (TypeError)

      if it cannot be coerced to a symbol

  • #default_request_formatSymbol?

    Gets the value

    Returns:

    • (Symbol, nil)

See Also:

Since:

  • 0.5.0



487
488
489
490
491
492
493
# File 'lib/hanami/controller/configuration.rb', line 487

def default_request_format(format = nil)
  if format
    @default_request_format = Utils::Kernel.Symbol(format)
  else
    @default_request_format
  end
end