Class: Volt::HttpController

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

Methods included from Actions

included, #run_actions, #stop_chain

Constructor Details

#initialize(volt_app, params, request) ⇒ HttpController

Initialzed with the params parsed from the route and the HttpRequest



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

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

Instance Attribute Details

#paramsObject

TODO params is only public for testing



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

def params
  @params
end

Instance Method Details

#perform(action = 'index') ⇒ Object



25
26
27
28
29
30
# File 'lib/volt/controllers/http_controller.rb', line 25

def perform(action='index')
  filtered = run_actions(:before, action)
  send(action.to_sym) unless filtered
  run_actions(:after, action) unless filtered
  respond
end