Kevin Howe
5/3/2005 10:54:00 PM
Very cool, this is along the lines of something I've been toying with for
the next version of Nemo (rubyforge.org/projects/nemo). Nemo tags class
attributes (traits) with display-related metadata, then later uses it to
render an html table or html edit form. The trait version might look
something like this:
class Foo
mtrait :name, :label=>'Full Name', :required=>true
mtrait :birthday, :type=>:date, :required=>true
end
foo = Foo.new
foo.name = 'Joe'
foo.birthday = Date.today
Editor.new(foo).render
This would display an html form with two required text fields labelled "Full
Name" and "Birthday". Hitting the save button updates the object instance
with the given input, assuming it passes all validations.
I've been wanting to abstract out the metadata definition into a generic
mechanism for defining metadata on any attribute, but if this were added to
traits that would pretty much be it. Thoughts?
Also, how does trains handle inheritance? Let's say we have A < B, then B
adds a few more traits, will A's @__trait data remain unaffected?
- Kevin