Skip to content

Instantly share code, notes, and snippets.

@beathyate
Forked from banker/Rails MongoMapper Template.rb
Created February 1, 2010 19:36
Show Gist options
  • Save beathyate/291935 to your computer and use it in GitHub Desktop.
Save beathyate/291935 to your computer and use it in GitHub Desktop.
# rails project_name -m http://gist.github.com/gists/291935.txt
# remove unneeded defaults
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/javascripts/controls.js"
run "rm public/javascripts/dragdrop.js"
run "rm public/javascripts/effects.js"
run "rm public/javascripts/prototype.js"
# add basic layout to start
file 'app/views/layouts/application.html.erb', <<HTML
<!DOCTYPE html>
<html lang="ea">
<head>
<title>Application!</title>
<meta charset="utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script>
<%= stylesheet_link_tag 'global' %>
</head>
<body>
<%= yield %>
</body>
</html>
HTML
# MongoDB FTW!
db_name = ask('What should I call the database? ')
initializer 'mongodb.rb', <<-CODE
if ENV['RACK_ENV'].present? && (ENV['RACK_ENV'] == 'production')
MongoMapper.connection = Mongo::Connection.new(ENV['DB_HOST'], ENV['DB_PORT'], :logger => Rails.logger)
end
MongoMapper.database = ENV['DB_NAME'] || "#{db_name}_#{Rails.env}"
if ENV['DB_USER'].present?
MongoMapper.database.authenticate(ENV['DB_USER'], ENV['DB_PASS'])
end
Dir[Rails.root + 'app/models/**/*.rb'].each do |model_path|
File.basename(model_path, '.rb').classify.constantize
end
MongoMapper.ensure_indexes!
CODE
file 'config/database.yml', <<-CODE
# Using MongoDB
CODE
# Don't need ActiveRecord
environment 'config.frameworks -= [:active_record]'
# MongoMapper
gem 'mongo', '0.18.2'
gem 'mongo_ext', '0.18.2'
gem 'mongo_mapper'
# Testing Helper
file 'test/test_helper.rb', <<-CODE
ENV['RAILS_ENV'] = 'test'
require File.expand_path(File.dirname(__FILE__) + '/../config/environment')
require 'test_help'
require 'shoulda'
require 'factory_girl'
class ActiveSupport::TestCase
# Drop all collections after each test case.
def teardown
MongoMapper.database.collections.each do |coll|
coll.remove
end
end
# Make sure that each test case has a teardown
# method to clear the db after each test.
def inherited(base)
base.define_method teardown do
super
end
end
end
CODE
# Testing tools
gem 'shoulda'
gem 'factory_girl'
# source control
file '.gitignore', <<-FILES
.DS_Store
**/.DS_Store
log/*
tmp/*
tmp/**/*
config/database.yml
bin/*
FILES
git :init
git :add => '.'
git :commit => '-a -m "Initial commit"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment