When I use an ORM like Sequel, the columns of a Model are defined by the connected database. How can I get a documentation for the columns of the table?
Example (Sequel, but I think the principle is the same for AR):
I create a table with this migration:
Sequel.migration do
up do
create_table(:person) do
primary_key :id
String :name, :null=>false
end
end
down do
drop_table(:person)
end
end
There is no way to add a column description to the database (or is there one? Please no DB-specific solution).
The corresponding Model is defined as
class Person < Sequel::Model
end
When I generate my documentation with rdoc, the documentation for Person is "empty", I get no description of the columns.
I can add a getter-method for a column like here:
class Person < Sequel::Model
#Name of the person
attr_reader :name
end
I get a description with rdoc, but there are two problems:
Person#name
is always nil, the connection to the DB is lost- And if it would work, it is a violation of the DRY-principle.
I could add a list of all columns:
#Columns:
# * name: Name of the person
# ...
class Person < Sequel::Model
end
But again:
- This breaks the DRY-principle.
- I want to see all available columns like a getter-methods.
I founds the annotate-gem. But this gem deletes previous comments and it adds only technical informations. I can not add comments.
Some other model frameworks such as datamapper, mongomaper and mongoid directly define the attributes in the models. (source) But I don't want to change my ORM.
So my question: What is the best-practice to store descriptions of the columns?