Class: Rack::Sprockets::Response
- Inherits:
-
Object
- Object
- Rack::Sprockets::Response
- Includes:
- Response::Helpers, Options
- Defined in:
- lib/rack/sprockets/response.rb
Overview
Given some generated js, mimicks a Rack::Response
> call to_rack to build standard rack response parameters
Constant Summary
Constants included from Options
Options::COLLECTION_OPTS, Options::RACK_ENV_NS
Instance Attribute Summary collapse
-
#body ⇒ Object
Rack response tuple accessors.
-
#headers ⇒ Object
Rack response tuple accessors.
-
#status ⇒ Object
Rack response tuple accessors.
Class Method Summary collapse
-
.content_length(body) ⇒ Object
Calculate appropriate content_length.
Instance Method Summary collapse
-
#initialize(env, js) ⇒ Response
constructor
Create a Response instance given the env and some generated js.
- #to_rack ⇒ Object
Methods included from Options
Constructor Details
#initialize(env, js) ⇒ Response
Create a Response instance given the env and some generated js.
30 31 32 33 34 35 36 37 38 |
# File 'lib/rack/sprockets/response.rb', line 30 def initialize(env, js) @env = env @body = js @status = 200 # OK @headers = Rack::Utils::HeaderHash.new headers["Content-Type"] = Rack::Sprockets::MIME_TYPE headers["Content-Length"] = self.class.content_length(body).to_s end |
Instance Attribute Details
#body ⇒ Object
Rack response tuple accessors.
13 14 15 |
# File 'lib/rack/sprockets/response.rb', line 13 def body @body end |
#headers ⇒ Object
Rack response tuple accessors.
13 14 15 |
# File 'lib/rack/sprockets/response.rb', line 13 def headers @headers end |
#status ⇒ Object
Rack response tuple accessors.
13 14 15 |
# File 'lib/rack/sprockets/response.rb', line 13 def status @status end |
Class Method Details
.content_length(body) ⇒ Object
Calculate appropriate content_length
18 19 20 21 22 23 24 |
# File 'lib/rack/sprockets/response.rb', line 18 def content_length(body) if body.respond_to?(:bytesize) body.bytesize else body.size end end |
Instance Method Details
#to_rack ⇒ Object
40 41 42 |
# File 'lib/rack/sprockets/response.rb', line 40 def to_rack [status, headers.to_hash, [body]] end |