Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bobbywilson0/290355 to your computer and use it in GitHub Desktop.
Save bobbywilson0/290355 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)
# 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.erb', <<-HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Application!</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/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
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'
# Testing tools
gem 'rspec'
gem 'rspec-rails'
gem 'factory_girl'
gem 'cucumber'
gem 'capybara'
# Gem management
rake 'gems:install'
generate :rspec
generate :cucumber
# 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