Skip to content

Instantly share code, notes, and snippets.

@jayzes
Forked from gvarela/Rails-3-App-Template.rb
Last active August 29, 2015 14:00
Show Gist options
  • Save jayzes/11277833 to your computer and use it in GitHub Desktop.
Save jayzes/11277833 to your computer and use it in GitHub Desktop.
Rails template for the base Mode Set stack
gem 'unicorn'
gem 'airbrake'
gem 'newrelic_rpm'
gem 'haml-rails'
gem_group :development, :test do
gem 'spring-commands-rspec', require: false
gem 'rspec-rails', github: 'rspec/rspec-rails'
gem 'teaspoon', github: 'modeset/teaspoon'
gem 'dotenv-rails'
gem 'pry-rails'
gem 'foreman'
end
gem_group :test do
gem 'shoulda-matchers'
gem 'capybara'
gem 'database_cleaner'
gem 'selenium-webdriver'
end
gem_group :staging, :production do
gem 'heroku-deflater'
gem 'lograge'
gem 'rails_12factor'
end
run 'bundle install'
# Set up generator defaults
generators = <<-RUBY
config.generators do |g|
g.template_engine :haml
g.stylesheets false
g.javascripts false
g.helpers false
g.test_framework :rspec, view_specs: false
end
RUBY
application generators
# Remove files we don't care about
remove_file "public/favicon.ico"
remove_file "README.rdoc"
say "Creating a nicer default README"
create_file 'README.md', <<-FILE.gsub(/^ {2}/, '')
#{app_name.humanize}
===========
* http://github.com/modeset/#{app_name}
* Application-specific documentation and notes go here.
FILE
# Create a sane robots.txt
robots_txt = <<-ROBOTS.gsub(/^ {2}/, '')
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
#
User-Agent: *
Disallow: /admin
ROBOTS
create_file "public/robots.txt", robots_txt
# Configure Unicorn and PRocfile
unicorn_config = <<-UNICORN_CONFIG.gsub(/^ {2}/, '')
worker_processes Integer(ENV['WEB_CONCURRENCY'] || 3)
timeout 10
preload_app true
listen ENV['PORT'].to_i || 3000, tcp_nopush: false
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
Rails.logger.info('Disconnected from ActiveRecord')
end
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
Rails.logger.info('Connected to ActiveRecord')
end
if Rails.cache.respond_to?(:reset)
Rails.cache.reset
Rails.logger.info('Rails cache has been reset')
end
end
UNICORN_CONFIG
create_file "config/unicorn.rb", unicorn_config
procfile = <<-PROCFILE.gsub(/^ {2}/, '')
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
PROCFILE
create_file "Procfile", procfile
# Keep the log and tmp directories intact
create_file "log/.gitkeep"
create_file "tmp/.gitkeep"
# Create a .gitignore file and a new local repository, commit everything
remove_file '.gitignore'
file '.gitignore', <<-CODE.gsub(/^ {2}/, '')
# System stuff
.DS_Store
.bundle
.idea
.rake_tasks
.rvmrc
.powenv
.env
REVISION
vendor/bundle
.rake_tasks~
mkmf.log
# Local config files
config/database.yml
# Local DBs
db/sphinx
db/*.sqlite3
# Logs
log/*.log
log/*.pid
# Tempfiles
tmp/
tmp/**/*
coverage
capybara*
# Assets
public/system
public/static
public/uploads
/assets
packages
CODE
# Tweak app layout to use HAML
layout = <<-LAYOUT.gsub(/^ {2}/, '')
!!!
%html
%head
%title #{app_name.humanize}
= stylesheet_link_tag :all
= javascript_include_tag :defaults
= csrf_meta_tag
%body
= yield
LAYOUT
remove_file "app/views/layouts/application.html.erb"
create_file "app/views/layouts/application.html.haml", layout
generate('rspec:install')
git :init
git :add => '.'
rails new <appname> -m <permalink> --database=postgresql --skip-test-unit --skip-keeps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment