lib/hanami/controller/configuration.rb in hanami-controller-0.7.1 vs lib/hanami/controller/configuration.rb in hanami-controller-0.8.0
- old
+ new
@@ -400,14 +400,28 @@
# # => Content-Type "application/custom"
# action.format # => :custom
def format(hash)
symbol, mime_type = *Utils::Kernel.Array(hash)
- @formats.merge! Utils::Kernel.String(mime_type) =>
- Utils::Kernel.Symbol(symbol)
+ @formats[Utils::Kernel.String(mime_type)] = Utils::Kernel.Symbol(symbol)
+ @mime_types = nil
end
+ # Return the configured format's MIME types
+ #
+ # @since 0.8.0
+ # @api private
+ #
+ # @see Hanami::Controller::Configuration#format
+ # @see Hanami::Action::Mime::MIME_TYPES
+ def mime_types
+ @mime_types ||= begin
+ ((@formats.keys - DEFAULT_FORMATS.keys) +
+ ::Rack::Mime::MIME_TYPES.values).freeze
+ end
+ end
+
# 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
@@ -648,9 +662,10 @@
def reset!
@handle_exceptions = true
@handled_exceptions = {}
@modules = []
@formats = DEFAULT_FORMATS.dup
+ @mime_types = nil
@default_request_format = nil
@default_response_format = nil
@default_charset = nil
@default_headers = {}
@cookies = {}