Created
May 31, 2010 05:16
-
-
Save assimovt/419566 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bundle_mongo_template.rb | |
# | |
# fork of Ben Scofield's Rails MongoMapper Template (http://gist.github.com/181842) | |
# | |
# This template: | |
# - Adds Bundler support | |
# - Adds MongoDB support | |
# - Removes default files and javascript | |
# - Installs common gems via bundler: mocha, shoulda, factory-girl, shoulda_generator, haml, mongrel | |
# | |
# Facts: | |
# - Tested with Rails 2.3.8, but should work with any 2.3.x | |
# - Uses git | |
# | |
# To use: | |
# - rails project_name -m http://gist.github.com/419566.txt | |
# - Don't forget to start the mongodb server | |
# | |
# 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" | |
BUNDLER_BOOT=<<DATA | |
class Rails::Boot | |
def run | |
load_initializer | |
Rails::Initializer.class_eval do | |
def load_gems | |
@bundler_loaded ||= Bundler.require :default, Rails.env | |
end | |
end | |
Rails::Initializer.run(:set_load_path) | |
end | |
end | |
Rails.boot! | |
DATA | |
inside 'config' do | |
data = File.read('boot.rb') | |
data.gsub!(/^Rails.boot!$/, BUNDLER_BOOT) | |
File.open('boot.rb', "w") do |file| | |
file.puts data | |
end | |
end | |
file 'config/preinitializer.rb', <<-CODE | |
begin | |
require "rubygems" | |
require "bundler" | |
rescue LoadError | |
raise "Could not load the bundler gem. Install it with `gem install bundler`." | |
end | |
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24") | |
raise RuntimeError, "Your bundler version is too old." + | |
"Run `gem install bundler` to upgrade." | |
end | |
begin | |
# Set up load paths for all bundled gems | |
ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__) | |
Bundler.setup | |
rescue Bundler::GemNotFound | |
raise RuntimeError, "Bundler couldn't find some gems." + | |
"Did you run `bundle install`?" | |
end | |
CODE | |
file 'Gemfile', <<-CODE | |
source "http://rubygems.org" | |
gem 'rails', '2.3.8' | |
gem 'mongo_mapper', '0.7.6' | |
gem 'bson_ext', '1.0' | |
gem 'mongo', '1.0' | |
gem 'haml' | |
group :development do | |
gem 'shoulda_generator' | |
gem 'mongrel' | |
end | |
group :test do | |
gem 'mocha' | |
gem 'shoulda' | |
gem 'factory_girl' | |
end | |
CODE | |
# MongoDB FTW! | |
db_name = ask('What should I call the database? ') | |
initializer 'database.rb', <<-CODE | |
MongoMapper.database = "#{db_name}-\#{Rails.env}" | |
if defined?(PhusionPassenger) | |
PhusionPassenger.on_event(:starting_worker_process) do |forked| | |
MongoMapper.connection.connect_to_master if forked | |
end | |
end | |
CODE | |
file 'config/database.yml', <<-CODE | |
# Using MongoDB | |
CODE | |
# Don't need ActiveRecord | |
environment 'config.frameworks -= [:active_record]' | |
# 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 'mocha' | |
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 | |
# Get dependencies | |
gem 'bundler' | |
run 'bundle install' | |
run 'bundle lock' | |
# source control | |
file '.gitignore', <<-FILES | |
.bundle | |
.DS_Store | |
**/.DS_Store | |
log/* | |
tmp/* | |
tmp/**/* | |
config/database.yml | |
coverage/* | |
coverage/**/* | |
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