Class: Tap::Controllers::App
Overview
Instance Attribute Summary
#action, #request, #response, #server
Instance Method Summary
collapse
#app, call, #empty_binding, inherited, #initialize, name, #persistence, #redirect, #render, #render_erb, #root, #route, #session, set, #uri
Instance Method Details
#call(env) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/tap/controllers/app.rb', line 12
def call(env)
server = env['tap.server'] ||= Tap::Server.new
if path = server.search(:public, env['PATH_INFO'])
content = File.read(path)
= {
"Last-Modified" => [File.mtime(path).httpdate],
"Content-Type" => [Rack::Mime.mime_type(File.extname(path), 'text/plain')],
"Content-Length" => [content.size.to_s]
}
[200, , [content]]
else
super
end
end
|
#help(key = nil) ⇒ Object
94
95
|
# File 'lib/tap/controllers/app.rb', line 94
def help(key=nil)
end
|
#index ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/tap/controllers/app.rb', line 30
def index
env_names = {}
server.env.minimap.each do |name, environment|
env_names[environment] = name
end
render('index.erb', :locals => {:env => server.env, :env_names => env_names}, :layout => true)
end
|
#info ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/tap/controllers/app.rb', line 39
def info
if request.post?
app.info
else
render('info.erb', :locals => {:update => true, :content => app.info}, :layout => true)
end
end
|
#run ⇒ Object
79
80
81
82
|
# File 'lib/tap/controllers/app.rb', line 79
def run
Thread.new { app.run }
redirect("/app/tail")
end
|
#stop ⇒ Object
84
85
86
87
|
# File 'lib/tap/controllers/app.rb', line 84
def stop
app.stop
redirect("/app/info")
end
|
#tail(id = nil) ⇒ Object
– Currently tail is hard-coded to tail the server log only.
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/tap/controllers/app.rb', line 49
def tail(id=nil)
begin
path = root.subpath(:log, 'server.log')
raise unless File.exists?(path)
rescue
raise Tap::ServerError.new("invalid path", 404)
end
pos = request['pos'].to_i
if pos > File.size(path)
raise Tap::ServerError.new("tail position out of range (try update)", 500)
end
content = File.open(path) do |file|
file.pos = pos
file.read
end
if request.post?
content
else
render('tail.erb', :locals => {
:id => id,
:path => File.basename(path),
:update => true,
:content => content
}, :layout => true)
end
end
|
#terminate ⇒ Object
89
90
91
92
|
# File 'lib/tap/controllers/app.rb', line 89
def terminate
app.terminate
redirect("/app/info")
end
|