Skip to content

kristianmandrup/mongo_rails3_gen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mongo DB generators

The Mongo DB Rails 3 generators includes generators for both Mongo Mapper and Mongoid.

Mongoid and Mongomapper now with Rails 3 generators

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.

Rails model maker

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.

Installation

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

Mongoid

Includes the following generators

  • mongoid:setup - setup Rails app to use Mongoid
  • mongoid:model - generates a Mongoid model

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

Mongo Mapper

Includes the following generators

  • mongo_mapper:setup - setup Rails app to use Mongo Mapper
  • mongo_mapper:model - generates a Mongo Mapper model

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

Notice

This is currently a work in progress. Please feel free to join in the effort and fork this project and help fix and improve.

About

Mongo DB rails 3 generators to setup use of Mongo DB and create Mongo DB compatible models in Rails 3

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages