Class: Sapp::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/sapp/response.rb

Overview

In charge of creating the tuple deciding Content-Type and returning status.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, handler) ⇒ Response

Returns a new instance of Response.



9
10
11
12
13
# File 'lib/sapp/response.rb', line 9

def initialize status, handler
  @status  = status
  @handler = handler
  @headers = Hash.new
end

Instance Attribute Details

#handlerObject (readonly)

Returns the value of attribute handler.



7
8
9
# File 'lib/sapp/response.rb', line 7

def handler
  @handler
end

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/sapp/response.rb', line 7

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/sapp/response.rb', line 7

def status
  @status
end

Instance Method Details

#process_handlerObject

With defaults



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sapp/response.rb', line 16

def process_handler
  case handler
    when String
      create_tuple 200, handler
    when Array
      handler
    when Hash
      add_header 'Content-Type', 'application/json' 
      create_tuple 200, handler.to_json
    else
      [500, {}, ["response must be a string, tuple, or hash"]]
  end
end