Catapult!

Overview

Catapult is a simple WEBrick instance that dynamically loads and executes objects defined by URL paths.

A Catapult instance assumes URLs follow a known structure:
http://host:8080/classname/path/info/stuff

This essentially translates to calling

load 'Classname.rb'
obj ||= Classname.new()
obj.run( "path/info/stuff" )

The results of calling run are then send back via WEBrick

Details

The Catapult request handler takes the first segment of the URL and assumes that it names a file that defines a class of the same name. The code first looks to see if an instance of the class exists in a cache. If so, it gets reused. If not, the code attempts to instantiate the object. Class and file names must be the same; you may use a lowercase name in the URL, but Catapult will change the first letter to uppercase before attempting to use the class.

Catapult will look for source files in the standard Ruby lib path, as well as in any directories given by the environment variable CATAPULT_PATH.

Objects loaded by Catapult must respond to these messages

Since objects are cached, the code cannot rely on fresh values passed via new. This also means you only need to initialize objects once. It should also mean that Catapult code can use persistent resources, such as Madeleine for storage.

(However: Catapult uses load rather than require and it is possible to clear an object from the cache. So you can write code that always instantiates a new instance, or loads code form disk on each call. But that is not the default behavior)

launch.rb

A second application, launch.rb, is provided to make running Catapult a bit easier. It allows you to define values for CATAPULT_PATH, and traps command-line interrupts to shut down the WEBrick instance. If you want to run the code under Windows, but do not want to have a cmd.exe window floating around, change the file extension to rbw. That will also stop you from being able to shut it down using CTRL-C, but you should always be able to stop the server by using the 'quit' URL (see Usage, below)

James Britt