SearchNavigation |
Some Rails plugins: acts_as_magic_modelSubmitted by gwolf on Sun, 04/13/2008 - 16:52.
This is the third plugin I have been working on for Rails - It's the one that still needs most work to be fully usable (for what I originally envisioned it), but is almost there - I have not touched it (nor the other two I recently presented here, acts_as_catalog and Real FK because real-life has demanded my time on various other fronts. Using the pluginIn order to use this plugin, you only have to declare it in your model. As an example, say you have the proverbial project-management system, where you have projects (each of which can be of several different types) and people, and a HABTM relation between people and projects. So, you have the following tables (expressed as migrations here):
Using acts_as_magic_model, you can skip declaring the relations in your models, like this: (of course, each of the classes still has to be declared in its own file)
And the gaps will be filled in for you - that is, you can go on and ask for Project.find(:first).people, ProjectType.find(:first).projects.size, Person.find(:first).projects.map {|pr| pr.project_type}, and whatever you fancy. In future versions of the plugin, I expect even to get rid to explicitly declare the class declarations. Of course, you should be warned: Initializing a model using this plugin is quite database-intensive. It will clutter your logs, and it might be unbearable if you use it in development mode. Still, its convenience is very often worth it. Its main uses should be when prototyping and when designing a system that needs to be flexible to the data models themselves - If you don't expect your system's data structures to be highly malleable, you should probably use acts_as_magic_model only as a prototyping aid.
( categories: )
|
Random Acidfree itemsTalks, papers and documents by categoryBlog posts by categoryCurrent weatherMexico City ![]()
Wed, 07/23/2008 - 19:51 |
Umm...
Are you aware of Dr. Nic's Magic Models plugin, which also infers validation rules, and actually even lets you skip defining any models *at all*? Now that's magic ;)
They look quite nice, at least from the description
I do not like over-magicizing too many things ;-) But yes, he went on quite a similar direction to mine. Thanks!
Post new comment