In message <000001c1b5c0$1b1bf590$85222fc0@sarion.co.jp>,
`"NAKAMURA, Hiroshi" <nahi@keynauts.com>' wrote:
> Is there any chance that notwork.org will have CVS
> repository for bricklet such as soaplet.rb, rwikilet.rb,
> tofulet, proc, xmlrpc4rlet(?), etc, etc...?
Sure, I hope they are bundled with our package.
I'd like to make a rule for writing samples.
Each servlet has different usage and requires another
packages. I think they should be pluggable so that
interested servelet can be chosen and performed.
So I wrote an httpd.rb (attached below).
If you run it as follows:
% ruby httpd.rb hoge
The server will enable servlets by following sequence:
require 'hoge'
setup_hoge(svr, "/hoge")
Hoge.rb must define setup_hoge(). It initialize
Hogelet and mount it on the server.
Any ideas?
--
gotoyuzo
#!/usr/bin/env ruby
require 'webrick'
require 'getopts'
getopts nil, "p:2000", "r:"
Servlets = $OPT_r
Port = $OPT_p
def setup(svr, servname)
begin
require "#{servname}"
send("setup_" + servname, svr, "/"+servname)
$stderr.puts "#{servname}: OK"
rescue Exception=> ex
$stderr.puts "#{servname}: failed"
$stderr.puts "#{ex.type}: #{ex.message}"
end
end
def main(argv)
logger = WEBrick::Log::new($stderr, WEBrick::Log::DEBUG)
svr = WEBrick::HTTPServer.new(
:BindAddress => "0.0.0.0",
:Port => Port,
:Logger => logger
)
trap(:INT){ svr.shutdown }
argv.each{|servlet| setup(svr, servlet) }
svr.start
end
main(ARGV)