Class: Alephant::Broker::Response::Base

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/alephant/broker/response/base.rb

Direct Known Subclasses

Asset, Batch, NotFound, ServerError, Status

Constant Summary collapse

STATUS_CODE_MAPPING =
{
  200 => "ok",
  202 => "Accepted",
  304 => "",
  404 => "Not found",
  500 => "Error retrieving content"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status = 200, content_type = "text/html", request_env = nil) ⇒ Base

Returns a new instance of Base.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/alephant/broker/response/base.rb', line 25

def initialize(status = 200, content_type = "text/html", request_env = nil)
  @content = STATUS_CODE_MAPPING[status]
  @headers = {
    "Content-Type"                 => content_type,
    "Access-Control-Allow-Headers" => "If-None-Match, If-Modified-Since",
    "Access-Control-Allow-Origin"  => "*"
  }
  @headers.merge!(Broker.config[:headers]) if Broker.config.key?(:headers)
  @status = status

  add_no_cache_headers if should_add_no_cache_headers?(status)
  add_etag_allow_header if headers.key?("ETag")
  setup if status == 200

  @content = "" if self.class.options?(request_env)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



15
16
17
# File 'lib/alephant/broker/response/base.rb', line 15

def content
  @content
end

#headersObject (readonly)

Returns the value of attribute headers.



15
16
17
# File 'lib/alephant/broker/response/base.rb', line 15

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



15
16
17
# File 'lib/alephant/broker/response/base.rb', line 15

def status
  @status
end