Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shingara/242007 to your computer and use it in GitHub Desktop.
Save shingara/242007 to your computer and use it in GitHub Desktop.
# mongo_template.rb
# fork of Ben Scofield's Rails MongoMapper Template (http://gist.github.com/181842)
# fork of Kyle Banker's Rails MongoMapper Template (http://gist.github.com/219223)
#
# To use:
# change url by raw link in http://gist.github.com/242007
# rails project_name -m http://gist.github.com/gists/242007.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"
run "rm -rf test"
# add basic layout to start
file 'app/views/layouts/application.html.haml', <<-HTML
!!! Strict
%html
%head
%title Application
%body
=yield
HTML
initializer 'mongodb.rb', <<-CODE
db_config = YAML::load(File.read(RAILS_ROOT + "/config/database.yml"))
if db_config[Rails.env] && db_config[Rails.env]['adapter'] == 'mongodb'
mongo = db_config[Rails.env]
MongoMapper.connection = Mongo::Connection.new(mongo['hostname'],
mongo['port'] || 27017,
:logger => Rails.logger)
MongoMapper.database = mongo['database']
MongoMapper.ensure_indexes!
end
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
MongoMapper.database.connect_to_master if forked
end
end
CODE
# MongoDB FTW!
db_name = ask('What should I call the database? ')
file 'config/database.yml', <<-CODE
development:
adapter: mongodb
database: #{db_name}_dev
# Warning: The database defined as "test" will be erased and
# # re-generated from your development database when you run "rake".
# # Do not set this db to the same as development or production.
test:
adapter: mongodb
database: #{db_name}_test
production:
adapter: mongodb
database: #{db_name}
CODE
# Don't need ActiveRecord
environment 'config.frameworks -= [:active_record]'
# MongoMapper
gem 'mongo'
gem 'mongo_ext'
gem 'mongo_mapper'
gem 'haml'
# Testing tools
gem 'rspec'
gem 'rspec-rails'
# Gem management
rake 'gems:install'
generate :rspec
# Rspec Helper
file 'spec/spect_helper.rb', <<-CODE
#This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
require 'spec/autorun'
require 'spec/rails'
# Uncomment the next line to use webrat's matchers
#require 'webrat/integrations/rspec-rails'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
Spec::Runner.configure do |config|
config.before(:each) do
MongoMapper.database.collections.each do |coll|
coll.remove
end
end
end
CODE
# 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