Class: Rack::Less::Response

Inherits:
Object
  • Object
show all
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

Options::RACK_ENV_NS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Options

included

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

#bodyObject

Rack response tuple accessors.



13
14
15
# File 'lib/rack/less/response.rb', line 13

def body
  @body
end

#headersObject

Rack response tuple accessors.



13
14
15
# File 'lib/rack/less/response.rb', line 13

def headers
  @headers
end

#statusObject

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_rackObject



40
41
42
# File 'lib/rack/less/response.rb', line 40

def to_rack
  [status, headers.to_hash, [body]]
end