Sha256: 76a2208962014d8e96fde9c9f0e165cfdeb9211c1865ecc85ca296fc6704dab4
Contents?: true
Size: 1.68 KB
Versions: 17
Compression:
Stored size: 1.68 KB
Contents
module Padrino module Generators module Components module Orms module MongomapperGen MONGO = (<<-MONGO).gsub(/^ {10}/, '') MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger) 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' create_file("config/database.rb", MONGO) empty_directory('app/models') end MM_MODEL = (<<-MODEL).gsub(/^ {10}/, '') class !NAME! include MongoMapper::Document # key <name>, <type> !FIELDS! end MODEL def create_model_file(name, fields) 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) end def create_model_migration(filename, name, fields) # NO MIGRATION NEEDED end def create_migration_file(migration_name, name, columns) # NO MIGRATION NEEDED end end end end end end
Version data entries
17 entries across 17 versions & 1 rubygems