Skip to content

Latest commit

 

History

History
57 lines (38 loc) · 1.76 KB

README.rdoc

File metadata and controls

57 lines (38 loc) · 1.76 KB

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 © 2009 Martin Gamsjaeger (snusnu). See LICENSE for details.