Class: Tap::Controllers::App

Inherits:
Tap::Controller show all
Includes:
RestRoutes
Defined in:
lib/tap/controllers/app.rb

Overview

:startdoc::controller dispatches signals to an app

Constant Summary

Constants inherited from Tap::Controller

Tap::Controller::ServerError

Instance Attribute Summary

Attributes inherited from Tap::Controller

#request, #response, #server

Instance Method Summary collapse

Methods inherited from Tap::Controller

#action?, call, #call, #error, get, inherited, #initialize, #module_render, nest, #not_found, #redirect, #render, #render_erb, #render_layout, set, set_variables

Constructor Details

This class inherits a constructor from Tap::Controller

Instance Method Details

#appObject



39
40
41
# File 'lib/tap/controllers/app.rb', line 39

def app
  server.app
end

#dispatch(route) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tap/controllers/app.rb', line 14

def dispatch(route)
  if route == "/"
    return render('index.erb', :layout => true)
  end
  
  route =~ Tap::Parser::SIGNAL
  signal = app.route($1, $2)
  
  request_method = request.request_method
  case request_method
  when /GET/i
    module_render('get.erb', signal)
  when /POST/i
    result = signal.call(request.params)
    module_render('post.erb', signal, :locals => {:result => result})
  else
    error("cannot signal via: #{request_method}")
  end
end

#routeObject



10
11
12
# File 'lib/tap/controllers/app.rb', line 10

def route
  unescape(request.path_info)
end

#uri(obj, sig = nil) ⇒ Object



34
35
36
37
# File 'lib/tap/controllers/app.rb', line 34

def uri(obj, sig=nil)
  obj, sig = nil, obj unless sig
  super(obj ? "#{obj}/#{sig}" : sig)
end