Skip to content

Instantly share code, notes, and snippets.

@johnmeehan
Last active May 1, 2018 21:49
Show Gist options
  • Save johnmeehan/a26d1ff5a2e1b553af0a to your computer and use it in GitHub Desktop.
Save johnmeehan/a26d1ff5a2e1b553af0a to your computer and use it in GitHub Desktop.
Basic Rails Setup (template)
# Rails Project Template
# Run with:
# rails new MyApp -T -m http://.............
# John Meehan 2016,2018
# Set the ruby version to that of the RVM
def set_ruby_version
insert_into_file('Gemfile', "ruby '#{RUBY_VERSION}'\n", :before => /^ *gem 'rails'/, :force => false)
# Set the Gemset name based on the Rails app name
insert_into_file('Gemfile', "#ruby-gemset=#{@app_name}\n", :before => /^ *gem 'rails'/, :force => false)
end
def add_gems
puts "****** Gemfile *******"
gem 'haml'
gem "haml-rails"
# gem 'bootstrap-sass'
gem_group :development, :test do
gem "rspec-rails"
gem 'spring-commands-rspec'
gem "factory_bot_rails"
end
gem_group :test do
gem 'database_cleaner'
# gem 'shoulda-matchers'
gem 'capybara'
# gem 'simplecov', :require => false
gem 'rubocop', require: false
end
gem_group :development do
gem 'annotate'
gem 'awesome_print'
gem 'guard'
gem 'guard-rspec', require: false
gem 'guard-livereload', require: false
gem 'guard-annotate', require: false
end
# puts "****** Bundle *******"
# run "bundle install"
end
def haml_setup
puts "****** After Bundle *******"
generate 'haml:application_layout convert' #converts application.erb to haml
run "rm app/views/layouts/application.html.erb"
end
def rspec_setup
generate 'rspec:install'
end
# def bootstrap_setup
# puts "******* Bootstrap *********"
# run "rm app/assets/stylesheets/application.css"
# file "app/assets/stylesheets/application.scss", <<-CODE
# @import "bootstrap-sprockets";
# @import "bootstrap";
# CODE
# insert_into_file('app/assets/javascripts/application.js', "\n//= require bootstrap-sprockets", :after => /^ *\/\/= require jquery_ujs/, :force => false)
# end
# puts "****** Binstub *******"
# run "bundle exec spring binstub --all"
def guard_setup
puts "****** Guard Init *******"
run "bundle exec guard init"
end
def setup_database_cleaner
file 'spec/support/database_cleaner.rb', <<-CONFIG
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
CONFIG
end
def git_setup
puts "****** GIT *******"
git :init
git add: "."
git commit: "-m 'First commit!'"
end
def run
add_gems
after_bundle do
haml_setup
rspec_setup
# bootstrap_setup
guard_setup
setup_database_cleaner
git_setup
end
puts "****** DONE ******"
end
run
## Rails will Run bundle install AND binsubs itself after this!
# John Meehan 2016,2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment