= dm-reflection
For now, this gem only allows you to print the ruby source for any DataMapper::Model, taking all property and relationship definitions into account. However, the plan is to be able to reflect on an existing relational database schema and export the corresponding datamapper model definitions to ruby source files. Think of it as active_record and annotate_models combined to do something useful with legacy databases.
require 'rubygems' require 'dm-core' require 'dm-reflection/builders/source_builder'
class Project
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true, :length => 200
property :created_at, DateTime
property :updated_at, DateTime
has 0..n, :project_tasks
has 0..n, :tasks, :through => :project_tasks
has 0..n, :people, :through => Resource
end
Project.to_ruby # produces this nicely formatted ruby code
<<-RUBY class Project
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true, :length => 200
property :created_at, DateTime
property :updated_at, DateTime
has 0..n, :project_tasks
has 0..n, :tasks, :through => :project_tasks
has 0..n, :people, :through => Resource
end RUBY
== Note on Patches/Pull Requests
== Copyright
Copyright (c) 2009 Martin Gamsjaeger (snusnu). See LICENSE for details.