Tuesday, 10 September 2013

Ruby DataMapper, table inheritance

Ruby DataMapper, table inheritance

My tables repeat this line always
property :created_at, DateTime, :default => DateTime.now, :lazy =>
[:show]
property :updated_at, DateTime, :default => DateTime.now, :lazy => [:show]
How do I DRY this out? Do I inherit, or have a module, or something else?
It's like this:
Class Foo
include DataMapper::Resource
property :id, Int
property :created_at, DateTime, :default => DateTime.now, :lazy => [:show]
property :updated_at, DateTime, :default => DateTime.now, :lazy => [:show]
end
Class Bar
include DataMapper::Resource
property :id, Int
property :created_at, DateTime, :default => DateTime.now, :lazy => [:show]
property :updated_at, DateTime, :default => DateTime.now, :lazy => [:show]
end
these are repeated multiple times through each of the table

No comments:

Post a Comment