Forum: Ruby on Rails ?: Quasi Aspect Oriented Programming with Plugins...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
F3158b6c62d112e4aba9579953e925db?d=identicon&s=25 Wybo Wiersma (wybo)
on 2007-04-06 14:11
(Received via mailing list)
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

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 (like Rails Engines).

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, Controllers
and (thanks to the body builder module) Views.

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 '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've called
build_bodies as a before_filter.

You can get the modules here:
(an extension to the module class is needed to allow mixing in both
class and normal methods...)

So now go forth and multiply your app's aspects...

If you think this module might be usefull for wider application I could
pack it up as a plugin. Also if you have any comments on how it could be
improved (in relation to yield for example) they're welcome...


Wybo Wiersma


- History, Informatiekunde (computer linguistics, IR, webtech) and
- Member of the Center for Metahistory Groningen

::Free Software and Open Source Developer:
-, Cumulative, shared commenting, publication
                           idea sharing: Where insight comes together...
- ComLinToo, a computational linguistics toolset written in Perl
- Lake ( Make), a make-replacement using makefiles in pure

- In the world, wavy hair, go figure
This topic is locked and can not be replied to.