class Sapp::Response

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

Attributes

handler[R]
headers[R]
status[R]

Public Class Methods

new(status, handler) click to toggle source
# File lib/sapp/response.rb, line 9
def initialize status, handler
  @status  = status
  @handler = handler
  @headers = Hash.new
end

Public Instance Methods

process_handler() click to toggle source

With defaults

# 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

Private Instance Methods

add_header(key, value) click to toggle source
# File lib/sapp/response.rb, line 32
def add_header key, value
  @headers[key] = value
end
create_tuple(default_status, body) click to toggle source

If status at initialization use, else use default

# File lib/sapp/response.rb, line 37
def create_tuple default_status, body
  [status ? status : default_status, headers, [body] ]
end