Sha256: 0fbc699ed4ed9c74b59f11b163cce8150f5a8fcd50d2f87ed62103a3e945997b

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 KB

Contents

MONGO = (<<-MONGO) 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_mapper'
  require_dependencies 'bson_ext', :require => 'mongo'
  require_dependencies('SystemTimer', :require => 'system_timer') if RUBY_VERSION =~ /1\.8/ && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')
  create_file("config/database.rb", MONGO.gsub(/!NAME!/, @project_name.underscore))
end

MM_MODEL = (<<-MODEL) unless defined?(MM_MODEL)
class !NAME!
  include MongoMapper::Document

  # key <name>, <type>
  !FIELDS!
  timestamps!
end
MODEL

# options => { :fields => ["title:string", "body:string"], :app => 'app' }
def create_model_file(name, options={})
  model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
  field_tuples = options[:fields].map { |value| value.split(":") }
  column_declarations = field_tuples.map { |field, kind| "key :#{field}, #{kind.underscore.camelize}" }.join("\n  ")
  model_contents = MM_MODEL.gsub(/!NAME!/, name.to_s.underscore.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

5 entries across 5 versions & 1 rubygems

Version Path
padrino-gen-0.11.4 lib/padrino-gen/generators/components/orms/mongomapper.rb
padrino-gen-0.11.3 lib/padrino-gen/generators/components/orms/mongomapper.rb
padrino-gen-0.11.2 lib/padrino-gen/generators/components/orms/mongomapper.rb
padrino-gen-0.11.1 lib/padrino-gen/generators/components/orms/mongomapper.rb
padrino-gen-0.11.0 lib/padrino-gen/generators/components/orms/mongomapper.rb