lib/padrino-gen/generators/components/orms/mongomapper_gen.rb in padrino-gen-0.6.3 vs lib/padrino-gen/generators/components/orms/mongomapper_gen.rb in padrino-gen-0.6.7
- old
+ new
@@ -4,29 +4,16 @@
module Orms
module MongomapperGen
MONGO = (<<-MONGO).gsub(/^ {10}/, '')
- class MongoDBConnectionFailure < RuntimeError; end
+ MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger)
- module DatabaseSetup
- def self.registered(app)
- app.configure :development do
- MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger)
- MongoMapper.database = 'your_dev_db_here'
- end
-
- app.configure :production do
- MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger)
- MongoMapper.database = 'your_production_db_here'
- end
-
- app.configure :test do
- MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger)
- MongoMapper.database = 'your_test_db_here'
- end
- end
+ case Padrino.env
+ when :development then MongoMapper.database = 'your_db_development'
+ when :production then MongoMapper.database = 'your_db_production'
+ when :test then MongoMapper.database = 'your_db_test'
end
MONGO
def setup_orm
require_dependencies 'mongo_mapper'
@@ -42,11 +29,10 @@
!FIELDS!
end
MODEL
def create_model_file(name, fields)
- model_path = app_root_path('app/models/', "#{name.to_s.underscore}.rb")
- return false if File.exist?(model_path)
+ model_path = destination_root('app/models/', "#{name.to_s.underscore}.rb")
field_tuples = fields.collect { |value| value.split(":") }
column_declarations = field_tuples.collect { |field, kind| "key :#{field}, #{kind.camelize}" }.join("\n ")
model_contents = MM_MODEL.gsub(/!NAME!/, name.to_s.camelize)
model_contents.gsub!(/!FIELDS!/, column_declarations)
create_file(model_path, model_contents)