1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| | # Usage: yahns -c /path/to/yahns/examples/the_metal.rb
# listens on port 6660 by default (change below)
$LOAD_PATH << "#{ENV['HOME']}/the_metal/lib"
require 'the_metal'
# based on README.markdown in git://github.com/tenderlove/the_metal.git
class Application
def call req, res
# TODO: to support persistent connections, we must have Content-Length
# when write_head is called or have Transfer-Encoding: chunked
# (in which case res.write must chunk for us)
res.write_head 200, 'Content-Type' => 'text/plain'
res.write "Hello World\n"
res.finish
end
end
class DBEvents
def start_app app
puts "ensure database connection"
end
def start_request req, res
puts "-> checkout connection"
end
def finish_request req, res
puts "<- checkin connection"
end
end
app = TheMetal.build_app([DBEvents.new], [], Application.new)
app(:the_metal, app) do
listen 6660
persistent_connections false # currently broken with TheMetal API..
end
|