Skip to content

Instantly share code, notes, and snippets.

@kirk
Forked from bscofield/gist:181842
Created October 23, 2009 03:59
Show Gist options
  • Save kirk/216632 to your computer and use it in GitHub Desktop.
Save kirk/216632 to your computer and use it in GitHub Desktop.
# rails_mongo_mapper.rb
#
# Code borrowed from Kyle Banker (who borrowed from Ben Scofield) and Justin Henry
#
# To use:
# rails project_name -m http://gist.github.com/gists/252053.txt
# Clear out stuff we won't use
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
run "rm -f public/javascripts/*"
run "rm -rf test/"
# Create the readme file
run "echo TODO: Explain yourself! > README.md"
# Setup required gems
gem 'haml'
gem 'mongo_mapper'
# Setup testing gems
#gem "cucumber", :lib => false, :environment => :test
gem "heckle", :lib => false, :environment => :test
gem "machinist_mongomapper", :lib => false, :environment => :test
gem "relevance-rcov", :lib => "rcov", :source => 'http://gems.github.com', :environment => :test
gem "remarkable_rails", :lib => false, :environment => :test
gem "rspec", :lib => false, :environment => :test
gem "rspec-rails", :lib => false, :environment => :test
#gem "webrat", :lib => false, :environment => :test
# Gem management
SUDO_CMD = yes?("Does gem installation require sudo on your system? (yes/no)") ? "true" : "false"
rake 'gems:install', :sudo => SUDO_CMD
#rake 'gems:unpack'
#rake 'rails:freeze:gems'
# add basic layout to start
# Generate haml plugin, and a default layout
run 'haml --rails .'
file 'app/views/layouts/application.html.haml', <<-HAML
!!!
%html
%head
%meta{ :content => "text/html; charset=utf-8", "http-equiv" => "content-type" }
%title Application!
%body
= yield
HAML
# 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]'
# MongoMapper
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 '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
# Testing tools
gem 'redgreen'
gem 'shoulda'
gem 'factory_girl'
gem 'mocha'
# Gem management
rake 'gems:install'
rake 'gems:unpack'
rake 'rails:freeze:gems'
# source control
file '.gitignore', <<-FILES
.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