Permalink
Browse files

Add rails 3 model generator.

  • Loading branch information...
cmeiklejohn committed Mar 25, 2011
1 parent 867f1cf commit d79ede021a82ee70b81be1a2e6783d430d0444db
@@ -0,0 +1,33 @@
# encoding: utf-8
module MongoMapper
module Generators
class ModelGenerator < Rails::Generators::NamedBase
desc 'Creates a mongomapper model'
argument :name, :type => :string
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
class_option :timestamps, :type => :boolean
check_class_collision
def self.source_root
@source_root ||= File.expand_path("../templates", __FILE__)
end
def create_model_file
template 'model.rb', File.join('app/models', "#{file_name}.rb")
end
hook_for :test_framework
end
end
end
module Rails
module Generators
class GeneratedAttribute #:nodoc:
def type_class
return type.to_s.camelcase
end
end
end
end
@@ -0,0 +1,11 @@
class <%= class_name %>
include MongoMapper::Document
<% attributes.each do |attribute| -%>
key :<%= attribute.name %>, <%= attribute.type_class %>
<% end -%>
<% if options[:timestamps] %>
timestamps!
<% end -%>
end

0 comments on commit d79ede0

Please sign in to comment.