Quasi Aspect Oriented Rails


If you've been programming for a while you've probably heard of [Aspect Oriented Programming].

Now AOP is good, as it reduces complexity for developers and when combined with modules it also allows system administrators more freedom in what parts of the software they want to run.

As Ruby is a very dynamic language (Mixins, and all classes are open) and [Rails] already provides quite some hooks like before-, after, and validation- filters in models and controllers we are already half way there.

Now even better: the excellent [plugins_plus plugin] already almost does what we want. It allows one to put code in their default places inside the lib (like app/models) that is then merged with your application's code automatically.

What is missing is a way to output data from plugins into existing views and layouts. For this I made the [BodyBuilderModule]. That module allows one to create hooks for places where content can be inserted in views.

In short it allows one to set body_parts (variables that can be included in views, like @pre_body) from controllers.

Together with the plugins_plus plugin this allows you to develop modules that mix in automatically at the level of Models, Views (thanks to the body builder module), and Controllers.

You can declare body-parts (variables like @left_body) inside a controller with:

body_parts :left, :pre # etc...

You should do this inside a plugin that is loaded before the plugins that will be adding to it. In case of Manta this is the [MantaModulizer plugin].

Now in other plugins (and in the main app) you can add to the body-parts with:

left_body :my_method, :my_other_method

(for this the body-part :left must have been declared)

Then in view in your app you can include @left_body, and it will contain all that my_method, my_other_method, (and possibly more methods in different modules) have returned after you called build_bodies as a before_filter.

So now go forth and multiply your app's aspects...
Part of the LogiLogi Network: The LogiLogi Foundation - LogiLogi.org - OgOg.org
This is an old version for archival purposes, see www.LogiLogi.org for the current version.
< Edit this document | View history | Printer friendly (inc. links) >
Visited 929 times
Document last modified Fri, 06 Apr 2007 15:10:46
All content is available under the GNU Free Documentation License. The LogiLogi-system is under the GPL
SourceForge.net Logo Zylon Internet Services-Groningen Logo
Visitor statistics