Sha256: 572f0dd564d929c35f7f745630461d3ee395145936069a4769c2e6a275110d1a

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

MONGO = (<<-MONGO).gsub(/^ {10}/, '') unless defined?(MONGO)
MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger)

case Padrino.env
  when :development then MongoMapper.database = '!NAME!_development'
  when :production  then MongoMapper.database = '!NAME!_production'
  when :test        then MongoMapper.database = '!NAME!_test'
end
MONGO

def setup_orm
  require_dependencies 'mongo_ext', :require => 'mongo'
  require_dependencies 'mongo_mapper'
  create_file("config/database.rb", MONGO.gsub(/!NAME!/, name.underscore))
  empty_directory('app/models')
end

MM_MODEL = (<<-MODEL).gsub(/^ {10}/, '') unless defined?(MM_MODEL)
class !NAME!
  include MongoMapper::Document

  # key <name>, <type>
  !FIELDS!
  timestamps!
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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
padrino-gen-0.9.10 lib/padrino-gen/generators/components/orms/mongomapper.rb