Class: Brut::FrontEnd::GenericResponse
- Inherits:
-
Object
- Object
- Brut::FrontEnd::GenericResponse
- Defined in:
- lib/brut/front_end/generic_response.rb
Overview
A generic response to use when no built-in Brut construct will suffice. This mirrors the response a Rack server is intended to produce, and serves as merely a typed wrapper around that kind of response for the purposes of understanding the intention of whoever is returning this.
Once created, #to_ary will convert this into the array that Rack requires.
Instance Method Summary collapse
-
#initialize(http_status: 200, headers: {}, response_body:) ⇒ GenericResponse
constructor
Create a generic response.
-
#to_ary ⇒ Array{String,3}
(also: #deconstruct)
Return this as an array suitable for use as a Rack response.
Constructor Details
#initialize(http_status: 200, headers: {}, response_body:) ⇒ GenericResponse
Create a generic response.
Note that this value must be a valid HTTP status.
through directly to the underlying Rack server so it should be whatever Rack expects, which is generally
something that responds to each
.
16 17 18 19 20 |
# File 'lib/brut/front_end/generic_response.rb', line 16 def initialize(http_status: 200, headers: {}, response_body:) @response_body = response_body @headers = headers @http_status = Brut::FrontEnd::HttpStatus.new(http_status.to_i) end |
Instance Method Details
#to_ary ⇒ Array{String,3} Also known as: deconstruct
Return this as an array suitable for use as a Rack response.
25 26 27 28 29 30 31 |
# File 'lib/brut/front_end/generic_response.rb', line 25 def to_ary [ @http_status.to_i, @headers, @response_body, ] end |