Class: Hanami::Action::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- Hanami::Action::Request
- Defined in:
- lib/hanami/action/request.rb
Overview
The HTTP request for an action, given to #handle.
Inherits from `Rack::Request`, providing compatibility with Rack functionality.
Instance Attribute Summary collapse
-
#params ⇒ BaseParams, Params
readonly
Returns the request's params.
Instance Method Summary collapse
- #accept ⇒ Object private
- #accept?(mime_type) ⇒ Boolean private
- #accept_header? ⇒ Boolean private
-
#flash ⇒ Flash
Returns the flash for the request.
-
#id ⇒ String
Returns the request's ID.
-
#initialize(env:, params:, sessions_enabled: false) ⇒ Request
constructor
private
A new instance of Request.
-
#session ⇒ Hash
Returns the session for the request.
Constructor Details
#initialize(env:, params:, sessions_enabled: false) ⇒ Request
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.
Returns a new instance of Request.
32 33 34 35 36 37 |
# File 'lib/hanami/action/request.rb', line 32 def initialize(env:, params:, sessions_enabled: false) super(env) @params = params @sessions_enabled = sessions_enabled end |
Instance Attribute Details
#params ⇒ BaseParams, Params (readonly)
Returns the request's params.
For an action with Validatable included, this will be a Params instance, otherwise a BaseParams.
28 29 30 |
# File 'lib/hanami/action/request.rb', line 28 def params @params end |
Instance Method Details
#accept ⇒ 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.
102 103 104 |
# File 'lib/hanami/action/request.rb', line 102 def accept @accept ||= @env[Action::HTTP_ACCEPT] || Action::DEFAULT_ACCEPT end |
#accept?(mime_type) ⇒ Boolean
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.
88 89 90 91 92 |
# File 'lib/hanami/action/request.rb', line 88 def accept?(mime_type) !!::Rack::Utils.q_values(accept).find do |mime, _| ::Rack::Mime.match?(mime_type, mime) end end |
#accept_header? ⇒ Boolean
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.
96 97 98 |
# File 'lib/hanami/action/request.rb', line 96 def accept_header? accept != Action::DEFAULT_ACCEPT end |
#flash ⇒ Flash
Returns the flash for the request.
78 79 80 81 82 83 84 |
# File 'lib/hanami/action/request.rb', line 78 def flash unless @sessions_enabled raise Hanami::Action::MissingSessionError.new("Hanami::Action::Request#flash") end @flash ||= Flash.new(session[Flash::KEY]) end |
#id ⇒ String
Returns the request's ID
45 46 47 48 |
# File 'lib/hanami/action/request.rb', line 45 def id # FIXME: make this number configurable and document the probabilities of clashes @id ||= @env[Action::REQUEST_ID] = SecureRandom.hex(Action::DEFAULT_ID_LENGTH) end |
#session ⇒ Hash
Returns the session for the request.
60 61 62 63 64 65 66 |
# File 'lib/hanami/action/request.rb', line 60 def session unless @sessions_enabled raise Hanami::Action::MissingSessionError.new("Hanami::Action::Request#session") end super end |