[Rails] abstract_naming_convention (proposal for new class)

Adelle Hartley adelle at bullet.net.au
Wed Jan 26 12:39:10 GMT 2005


Alexey Verkhovsky wrote:
> But let's go one step further and call it AbstractModel, a 
> class that would (similar to ApplicationController) contain 
> behaviors common for all model classes, _including_ the DB 
> naming convention. In both Rails applications I wrote to date 
> some such construct was needed.

A model contains multiple naming conventions, because different naming
conventions can be used for naming tables vs naming indexes vs naming
classes vs naming stored procedures vs naming other objects.

So I see abstract_naming_convention as a more basic/fundamental building
block than AbstractModel - although AbstractModel sounds like a good idea.
I haven't played with ApplicationController yet, but I think I understand
your analogy.

The only requirement for a naming_convention implementation would be that it
is reversible.

ie:  NamingConvention::decode(NamingConvention::encode(x)) == x

I envisage that to get from a table name to a class name would require two
naming_convention implementations.  eg:

	class_name =
ClassNamingConvention::encode(TableNamingConvention::decode(table_name))

I had previously thought of (and discarded) the idea of a class that would
do the translation from table name to class name in a single step.  Such a
class would be faster, but breaking it into two classes provides a lot more
flexibility.

Adelle.





More information about the Rails mailing list