Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

DataMapper plugin that will allow to generate models source files from existing relational databases.

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.rdoc

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

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2009 Martin Gamsjaeger (snusnu). See LICENSE for details.

Something went wrong with that request. Please try again.