The Mongo DB Rails 3 generators includes generators for both Mongo Mapper and Mongoid.
These generators have now been integrated into my forks of mongomapper and mongoid. Please let me know if they work there just as well and any ideas for further improvements.
I also have a rails_model_maker project in the works on my github account. This allows a rails model "graph" be defined in yaml and all the rails model files can be generated for the model framework of choice (ActiveRecord, Datamapper, MongoMapper, Mongoid etc.).
Please assist in the effort to finish the rails_model_maker project and add "plugins" for whichever model framework you like.
Add the following to your Gemfile in your Rails 3 project:
Note: Always check if there is a more recent or better fork to use...
gem 'mongo_ext' gem 'mongoid', :git => 'http://github.com/kristianmandrup/mongoid.git' gem "mongo_mapper", :git => 'http://github.com/kristianmandrup/mongomapper.git' $ bundle install
Includes the following generators
Example Use:
Setup use of Mongoid
rails g mongoid:setup
Create new model Person with name attribute
rails g mongoid:model person name:string => class Person field :name, :type => String end
Create document Address with attributes defaulting to string
rails g mongoid:model Address name street => class Address include Mongoid::Timestamps field :name, :type => String field :street, :type => String end
Add Timestamps using -T (true by default)
rails g mongoid:model person name:string -T => class Person < Being include Mongoid::Timestamps field :name, :type => String end
Add Versioning using -V (false by default)
rails g mongoid:model person name:string -V => class Person < Being include Mongoid::Versioning field :name, :type => String end
Index select attributes by postfixing name with #
rails g mongoid:model person name:string# -V => class Person < Being field :person, :type => String index :name, :unique => true end
Create Embedded document Browser as a kind of Being (Inheritance)
rails g mongoid:model person name:string --inherit canvas => class Person < Being field :person, :type => String end
Includes the following generators
Example Use:
Setup use of Mongo Mapper
rails g mongoid:setup
Create new Mongo Mapper model Person with name attribute
rails g mongoid:model person name:string
Create Embedded document Address with attributes defaulting to string
rails g mongoid:model address name street --embedded
This is currently a work in progress. Please feel free to join in the effort and fork this project and help fix and improve.