Class: Volt::HttpController

Inherits:
Object show all
Includes:
LifecycleCallbacks, LoginAsHelper
Defined in:
lib/volt/controllers/http_controller.rb

Overview

Allow you to create controllers that act as http endpoints

Instance Method Summary collapse

Methods included from LoginAsHelper

#login_as

Methods included from LifecycleCallbacks

included, #run_callbacks, #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
  @initial_params = params
end

Instance Method Details

#cookiesObject



32
33
34
# File 'lib/volt/controllers/http_controller.rb', line 32

def cookies
  @cookies ||= Volt::Model.new(request.cookies, persistor: Volt::Persistors::HttpCookiePersistor)
end

#paramsObject



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

def params
  @params ||= begin
    params = request.params.symbolize_keys.merge(@initial_params)
    Volt::Model.new(params, persistor: Volt::Persistors::Params)
  end
end

#perform(action = 'index') ⇒ Object



36
37
38
39
40
41
# File 'lib/volt/controllers/http_controller.rb', line 36

def perform(action='index')
  filtered = run_callbacks(:before_action, action)
  send(action.to_sym) unless filtered
  run_callbacks(:after_action, action) unless filtered
  respond
end