Skip to content
Browse files

Getting started

  • Loading branch information...
0 parents commit c74a7da41d911830982e0e8cd8893d318ab85cf5 @stympy committed
3 .gitignore
@@ -0,0 +1,3 @@
+Manifest
+pkg
+doc
3 CHANGELOG
@@ -0,0 +1,3 @@
+0.1.0 (24 July 2009)
+
+* initial release
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Benjamin Curtis
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 README.rdoc
@@ -0,0 +1,24 @@
+= Mongo Generators
+
+Mongo-related Rails generator scripts.
+
+
+== Install
+
+ gem install mongo-generators
+
+
+== Usage
+
+Once you install the gem, the generators will be available to all Rails
+applications on your system. If you run script/generate without any
+additional arguments you should see the available generators listed.
+
+To run the generator, go to your rails project directory and call it
+using the script/generate or script/destroy command.
+
+ script/generate mongo_model Post name:string body:string published:boolean
+
+== Thanks
+
+Thanks to Ryan Bate's nifty-generators for being the scaffold of this project. :)
15 Rakefile
@@ -0,0 +1,15 @@
+require 'rubygems'
+require 'rake'
+require 'echoe'
+
+Echoe.new('mongo-generators', '0.1.0') do |p|
+ p.project = "mongogenerators"
+ p.description = "MongoDB-related generator scripts for Rails."
+ p.url = "http://github.com/stympy/mongo-generators"
+ p.author = 'Benjamin Curtis'
+ p.email = "benjamin.curtis@gmail.com"
+ p.ignore_pattern = ["script/*"]
+ p.development_dependencies = []
+end
+
+Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
3 lib/mongo_generators.rb
@@ -0,0 +1,3 @@
+module MongoGenerators
+ # nothing to see here, the real action is under rails_generators
+end
16 rails_generators/mongo_model/USAGE
@@ -0,0 +1,16 @@
+Description:
+ Stubs out a new model. Pass the model name, either CamelCased or
+ under_scored, and an optional list of attribute pairs as arguments.
+
+ Attribute pairs are key_name:mongo_type arguments specifying the
+ model's attributes. Timestamps are added by default.
+
+Examples:
+ `./script/generate model account`
+
+ creates an Account model:
+ Model: app/models/account.rb
+
+ `./script/generate model post title:string body:string published:boolean`
+
+ creates a Post model with a string title, string body, and published flag.
24 rails_generators/mongo_model/mongo_model_generator.rb
@@ -0,0 +1,24 @@
+class MongoModelGenerator < Rails::Generator::NamedBase
+ def manifest
+ record do |m|
+ m.directory 'app/models'
+ m.template 'model.rb', "app/models/#{file_name}.rb"
+ end
+ end
+
+ protected
+
+ def attributes
+ @attributes ||= @args.collect do |attribute|
+ MongoAttribute.new(*attribute.split(":"))
+ end
+ end
+end
+
+class MongoAttribute
+ attr_accessor :name, :type
+
+ def initialize(name, type)
+ @name, @type = name, type.capitalize
+ end
+end
7 rails_generators/mongo_model/templates/model.rb
@@ -0,0 +1,7 @@
+class <%= class_name %>
+ include MongoMapper::Document
+
+<% for attribute in attributes -%>
+ key :<%= attribute.name %>, <%= attribute.type %>
+<% end -%>
+end
2 tasks/deployment.rake
@@ -0,0 +1,2 @@
+desc "Build the manifest and gemspec files."
+task :build => [:build_manifest, :build_gemspec]

0 comments on commit c74a7da

Please sign in to comment.
Something went wrong with that request. Please try again.