class Server

Public Class Methods

new(repo) click to toggle source
# File lib/vcs-ann/main.rb, line 69
def initialize(repo)
  @repo = repo
  @httpd = WEBrick::HTTPServer.new(
   :BindAddress => '127.0.0.1',
   :Port => 0,
   :AccessLog => NullLog,
   :Logger => NullLog)
  @httpd.mount_proc("/") {|req, res|
    handle_request0(repo, req, res)
  }
  trap(:INT){ @httpd.shutdown }
  addr = @httpd.listeners[0].connect_address
  @http_root = "http://#{addr.ip_address}:#{addr.ip_port}"
  @th = Thread.new { @httpd.start }
end

Public Instance Methods

annotate_url(relpath, rev) click to toggle source
# File lib/vcs-ann/main.rb, line 90
def annotate_url(relpath, rev)
  reluri = relpath.gsub(%r{[^/]+}) { CGI.escape($&) }
  reluri = '/' + reluri if %r{\A/} !~ reluri
  "#{@http_root}/file/#{rev}#{reluri}"
end
handle_request(repo, req, res) click to toggle source
# File lib/vcs-ann/main.rb, line 111
def handle_request(repo, req, res)
  res.content_type = 'text/html'
  list = req.request_uri.path.scan(%r{[^/]+}).map {|s| CGI.unescape(s) }
  case list[0]
  when 'file'
    res.body = repo.format_file list[1..-1]
  when 'commit'
    res.body = repo.format_commit list[1..-1]
  else
    raise "unexpected command"
  end
end
handle_request0(repo, req, res) click to toggle source
# File lib/vcs-ann/main.rb, line 96
def handle_request0(repo, req, res)
  begin
    handle_request(repo, req, res)
  rescue Exception
    res.content_type = 'text/html'
    result = '<pre>'
    result << "#{h $!.message} (#{h $!.class})\n"
    $!.backtrace.each {|b|
      result << "#{h b}\n"
    }
    result << "</pre>"
    res.body = result
  end
end
stop() click to toggle source
# File lib/vcs-ann/main.rb, line 85
def stop
  @httpd.shutdown
  @th.join
end