Writing Waffle controllers in Ruby
Waffle provides built in support for Ruby, allowing you to easily write your controllers in Ruby. The integration is
simple and straightforward, taking advantage of functionality Waffle provides (without the Rails!).
A key feature of Waffle has always been its pluggable architecture. From the beginning we believed that the default
behavior defined by the Waffle team might not be suitable for every situation. Therefor Waffle was built following an
Interface driven approach. Practically all of Waffle's built-in functionality can easily be extended or replaced. This
design made integrating Ruby support quite easy. The next 4 steps give a brief overview of how to integrate Ruby support
into your Waffle based applications.
Step 1
- Ensure dependency on waffle-ruby module
Step 2
- configure Waffle to be "Ruby Aware"
Waffle avoids XML like the plague but we still need to have a web.xml for our applications. This web.xml is where we can
take advantage of Waffle's pluggability. The following three context-param nodes need to be added to your applications
web.xml. This alerts Waffle that a few of its foundational components should be replaced with alternate implementations.
Step 3
- Your application's Registrar should extended
RubyScriptedRegistrar
to register your script as a controller:
In this example the Ruby class named 'FooBar' will be exposed as a controller under the name 'foobar' (e.g.
http://localhost:8080/ruby-webapp/foobar.waffle).
Step 4
- Write your Ruby controller class. Notice in the following example that your class does not need to extend or include
anything.
And that is all the steps required to integrate Ruby within your Waffle Applications.