Module: Lotus::Action::Mime
- Defined in:
- lib/lotus/action/mime.rb
Overview
Mime type API
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- HTTP_ACCEPT =
The key that returns accepted mime types from the Rack env
'HTTP_ACCEPT'.freeze
- CONTENT_TYPE =
The header key to set the mime type of the response
'Content-Type'.freeze
- DEFAULT_ACCEPT =
The default mime type for an incoming HTTP request
'*/*'.freeze
- DEFAULT_CONTENT_TYPE =
The default mime type that is returned in the response
'application/octet-stream'.freeze
Class Method Summary collapse
-
.included(base) ⇒ Object
private
Override Ruby’s hook for modules.
Instance Method Summary collapse
-
#content_type ⇒ String
The content type that will be automatically set in the response.
-
#format ⇒ Symbol
Returns a symbol representation of the content type.
Class Method Details
.included(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Override Ruby’s hook for modules. It includes Mime types logic
40 41 42 |
# File 'lib/lotus/action/mime.rb', line 40 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#content_type ⇒ String
The content type that will be automatically set in the response.
It prefers, in order:
* Explicit set value (see #format=)
* Weighted value from Accept
* Default content type
To override the value, use #format=
175 176 177 |
# File 'lib/lotus/action/mime.rb', line 175 def content_type @content_type || accepts || default_content_type || DEFAULT_CONTENT_TYPE end |
#format ⇒ Symbol
Returns a symbol representation of the content type.
The framework automatically detects the request mime type, and returns the corresponding format.
However, if this value was explicitely set by ‘#format=`, it will return that value
142 143 144 |
# File 'lib/lotus/action/mime.rb', line 142 def format @format ||= detect_format end |