Class: Rack::Less::Response
- Inherits:
-
Object
- Object
- Rack::Less::Response
- Includes:
- Options, Response::Helpers
- Defined in:
- lib/rack/less/response.rb
Overview
Given some generated css, mimicks a Rack::Response
> call to_rack to build standard rack response parameters
Constant Summary
Constants included from Options
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, css) ⇒ Response
constructor
Create a Response instance given the env and some generated css.
- #to_rack ⇒ Object
Methods included from Options
Constructor Details
#initialize(env, css) ⇒ Response
Create a Response instance given the env and some generated css.
30 31 32 33 34 35 36 37 38 |
# File 'lib/rack/less/response.rb', line 30 def initialize(env, css) @env = env @body = css @status = 200 # OK @headers = Rack::Utils::HeaderHash.new headers["Content-Type"] = Rack::Less::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/less/response.rb', line 13 def body @body end |
#headers ⇒ Object
Rack response tuple accessors.
13 14 15 |
# File 'lib/rack/less/response.rb', line 13 def headers @headers end |
#status ⇒ Object
Rack response tuple accessors.
13 14 15 |
# File 'lib/rack/less/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/less/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/less/response.rb', line 40 def to_rack [status, headers.to_hash, [body]] end |