while building a small CMS I now have the problem to create some
content elements. To be able to make a selectbox (or something
similar), I have to figure out, which content elements (each has its
own model-class) exist.
My plan was to extend the model-classes with some kind of module to
add some common methods and use
self.included(class) in the module to get all classes which include
this module. But the problem is, that this method is only called when
an instance of the class is created.
So the question is, how do I fetch all classes? Is there a common way
to do this and/or do I have to iterate over the files and read this
out (and how is this done )?
Maybe to give it a more general touch and clearify things a little:
The problem is, that I need some kind of configuration and I have to
know, what kind of content elements exist in the application.
One approach would be to have a configuration-file (yaml) or db-table
and say there something like: content_elements = text, image…
The problem would be, that if I want to add another type of element, I
have to edit this file or the db field.
Instead I want to have the opportunity to create a list of all content
elements at runtime and so make it possible to add different types of
content elements by only saying “acts_as_content_element” (for eg.) in
a model class. The problem is, that I have to find a way to know the
models, which are content elements.
Anybody came over this problem yet? Would this be a good approach and
how can I do this? Or is the usage of some kind of configuration-file
the better way?
I think in the future developement of this project I’m going to hit
this problem again, when it comes to the creation of a menu based on a
few specific controllers, so the solution has to fit here as well.
Maybe someone as a general (or the better a more detailed) solution?!?