Class: WebRouter::Controller

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

Constant Summary collapse

RESPONSE_TYPES =
{
  text: ['text/plain', -> (c) { c.to_s }],
  json: ['application/json', -> (c) { Oj.dump(c) }],
  html: ['text/html', ->(c) { c }]
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.action(action_name) ⇒ Object



16
17
18
# File 'lib/web_router/controller.rb', line 16

def self.action(action_name)
  proc { |env| new(action_name).call(env)}
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/web_router/controller.rb', line 8

def call(env)
  @env = env
  @request = Rack::Request.new(env)
  @request.params.merge!(env['router.params'] || {})
  send(@action_name)
  [200, @response_headers, [@response_body]]
end