Class: Zleb::Controller

Inherits:
Object show all
Defined in:
lib/zleb/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Controller

Returns a new instance of Controller.



4
5
6
7
8
9
10
# File 'lib/zleb/controller.rb', line 4

def initialize(opts = {})
  @request = opts[:request]
  @response = opts[:response]
  @headers = opts[:headers]
  @params = opts[:params]
  @scope = opts[:scope]
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



3
4
5
# File 'lib/zleb/controller.rb', line 3

def headers
  @headers
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/zleb/controller.rb', line 3

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



3
4
5
# File 'lib/zleb/controller.rb', line 3

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/zleb/controller.rb', line 3

def response
  @response
end

#scopeObject (readonly)

Returns the value of attribute scope.



3
4
5
# File 'lib/zleb/controller.rb', line 3

def scope
  @scope
end

Instance Method Details

#initObject



12
13
14
# File 'lib/zleb/controller.rb', line 12

def init
  # called after new and before method
end

#params_symObject



16
17
18
19
20
21
22
23
# File 'lib/zleb/controller.rb', line 16

def params_sym
  @params_sym = @params_sym || 
    if params
      SymbolizeHelper.symbolize_recursive(params)
    else
      params
    end
end

#throw_error(message, code) ⇒ Object



25
26
27
28
29
30
# File 'lib/zleb/controller.rb', line 25

def throw_error(message, code)
  response.status = code
  response['Content-Type'] = 'application/json'
  response.write(message.to_json)
  throw :halt, response.finish
end