Hi Alex,

This is as good a place as any for the time being.

So, the way that Rack works is that it takes an app *object* (not a class) and 
calls the "call" method on that object each time a request comes in. To 
facilitate the use of middleware and the combination of multiple Rack "app 
objects" in one server process, Rack also comes with a builder which uses a 
minimal DSL to collect these objects. What you're using is that builder DSL. 
So, to break it down:

> map '/foo' do
# The 'map' keyword in the DSL tells Rack that any time a request that starts 
with "/foo" comes in, it should use the app contained inside this block (which 
Rack finds by #call'ing the block passed to 'map' at start up.
>       $text = "foo"
>       print $text
# This is setup that will occur when Rack first #call's the block
>     run Proc.new {|env| [200, {"Content-Type" => "text/html"}, $text ] }
# The 'run' keyword tells Rack that the argument following 'run' is the "app 
object". In this case, you've provided a Proc object. Each HTTP request that 
comes in, with a path starting with "/foo", will #call this Proc object. Put 
your "print $text" line inside the block passed to Proc.new, and you'll see it 
getting called each time.
> end

If you're curious about the Rack::Builder DSL, the entire thing is only 55 
lines. You can find it in the ControlTower project in 
lib/control_tower/vendor/rack/builder.rb

Cheers,

Josh
_______________________________________________
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to