Class: Volt::HttpController

Inherits:
Object show all
Defined in:
lib/volt/controllers/http_controller.rb

Overview

Allow you to create controllers that act as http endpoints

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, request) ⇒ HttpController

Initialzed with the params parsed from the route and the HttpRequest



11
12
13
14
15
16
# File 'lib/volt/controllers/http_controller.rb', line 11

def initialize(params, request)
  @response_headers = HttpResponseHeader.new
  @response_body = []
  @request = request
  @params = Volt::Model.new(params.symbolize_keys.merge(request.params))
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/volt/controllers/http_controller.rb', line 8

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



8
9
10
# File 'lib/volt/controllers/http_controller.rb', line 8

def request
  @request
end

#response_bodyObject

Returns the value of attribute response_body.



7
8
9
# File 'lib/volt/controllers/http_controller.rb', line 7

def response_body
  @response_body
end

#response_headersObject (readonly)

Returns the value of attribute response_headers.



8
9
10
# File 'lib/volt/controllers/http_controller.rb', line 8

def response_headers
  @response_headers
end

Instance Method Details

#perform(action) ⇒ Object



18
19
20
21
22
23
# File 'lib/volt/controllers/http_controller.rb', line 18

def perform(action)
  # TODO: before actions
  send(action.to_sym)
  # TODO: after actions / around actions
  respond
end