Last active
April 22, 2017 06:28
-
-
Save nnabeyang/435005a54c23865642fb93728a242950 to your computer and use it in GitHub Desktop.
Ruby on Railsのrails new用のテンプレート
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Guardのマッチング規則を定義 | |
guard :minitest, spring: "bin/rails test", all_on_start: false do | |
watch(%r{^test/(.*)/?(.*)_test\.rb$}) | |
watch('test/test_helper.rb') { 'test' } | |
watch('config/routes.rb') { integration_tests } | |
watch(%r{^app/models/(.*?)\.rb$}) do |matches| | |
"test/models/#{matches[1]}_test.rb" | |
end | |
watch(%r{^app/controllers/(.*?)_controller\.rb$}) do |matches| | |
resource_tests(matches[1]) | |
end | |
watch(%r{^app/views/([^/]*?)/.*\.html\.erb$}) do |matches| | |
["test/controllers/#{matches[1]}_controller_test.rb"] + | |
integration_tests(matches[1]) | |
end | |
watch(%r{^app/helpers/(.*?)_helper\.rb$}) do |matches| | |
integration_tests(matches[1]) | |
end | |
watch('app/views/layouts/application.html.erb') do | |
'test/integration/site_layout_test.rb' | |
end | |
watch('app/helpers/sessions_helper.rb') do | |
integration_tests << 'test/helpers/sessions_helper_test.rb' | |
end | |
watch('app/controllers/sessions_controller.rb') do | |
['test/controllers/sessions_controller_test.rb', | |
'test/integration/users_login_test.rb'] | |
end | |
watch('app/controllers/account_activations_controller.rb') do | |
'test/integration/users_signup_test.rb' | |
end | |
watch(%r{app/views/users/*}) do | |
resource_tests('users') + | |
['test/integration/microposts_interface_test.rb'] | |
end | |
end | |
# 与えられたリソースに対応する統合テストを返す | |
def integration_tests(resource = :all) | |
if resource == :all | |
Dir["test/integration/*"] else | |
Dir["test/integration/#{resource}_*.rb"] | |
end | |
end | |
# 与えられたリソースに対応するコントローラのテストを返す | |
def controller_test(resource) | |
"test/controllers/#{resource}_controller_test.rb" | |
end | |
# 与えられたリソースに対応するすべてのテストを返す | |
def resource_tests(resource) | |
integration_tests(resource) << controller_test(resource) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#usage: ./init.sh <APP_PATH> | |
curl https://gist.githubusercontent.com/nnabeyang/435005a54c23865642fb93728a242950/raw/template.rb > template.rb | |
rails _5.0.0.1_ new $1 -m template.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def config_bundle | |
empty_directory ".bundle" | |
create_file(".bundle/config") do <<'RUBY' | |
--- | |
BUNDLE_JOBS: 4 | |
BUNDLE_WITHOUT: "production" | |
RUBY | |
end | |
end | |
remove_file "Gemfile" | |
run "touch Gemfile" | |
add_source 'https://rubygems.org' | |
gem 'rails', '5.0.0.1' | |
gem 'puma', '3.4.0' | |
gem 'sass-rails', '5.0.6' | |
gem 'uglifier', '3.0.0' | |
gem 'coffee-rails', '4.2.1' | |
gem 'jquery-rails', '4.1.1' | |
gem 'turbolinks', '5.0.1' | |
gem 'jbuilder', '2.4.1' | |
gem_group :development, :test do | |
gem 'sqlite3', '1.3.11' | |
gem 'byebug', '9.0.0', platform: :mri | |
end | |
gem_group :development do | |
gem 'web-console', '3.1.1' | |
gem 'listen', '3.0.8' | |
gem 'spring', '1.7.2' | |
gem 'spring-watcher-listen', '2.0.0' | |
end | |
gem_group :test do | |
gem 'rails-controller-testing', '0.1.1' | |
gem 'minitest-reporters', '1.1.9' | |
gem 'guard', '2.13.0' | |
gem 'guard-minitest', '2.4.4' | |
gem 'terminal-notifier-guard', '1.6.4' | |
end | |
gem_group :production do | |
gem 'pg', '0.18.4' | |
end | |
config_bundle | |
route "root 'welcome#index'" | |
inject_into_file "test/test_helper.rb", after: "require 'rails/test_help'" do<<'RUBY' | |
require 'minitest/reporters' | |
Minitest::Reporters.use! | |
RUBY | |
end | |
inject_into_file "config/application.rb", after: "# -- all .rb files in that directory are automatically loaded." do<<'RUBY' | |
config.generators do |g| | |
g.assets false | |
end | |
RUBY | |
end | |
after_bundle do | |
run "bin/spring stop" | |
get 'https://gist.githubusercontent.com/nnabeyang/435005a54c23865642fb93728a242950/raw/Guardfile', 'Guardfile' | |
generate "controller", "Welcome index" | |
generate "model", "user name:string email:string" | |
run "rails db:migrate" | |
git :init | |
git add: "." | |
git commit: "-a -m 'Initial commit'" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment