View
140
Download
3
Category
Preview:
Citation preview
Rails Application TemplateHamamatsu.rb
@jacoyutorius
Hamamatsu.rb 1
yuto ogi
4 @jacoyutorius
4 ruby, javascript
4 Hamamatsu.rb, JAWS-UG Hamamatsu
4 FOURIER.Inc
Hamamatsu.rb 2
Application Template
4 Railsの初期設定を定義するDSL
4 rails new時に実行
Hamamatsu.rb 3
sample
template.rb
gem "date_validator"gem "email_validator"
Hamamatsu.rb 4
sample
rails new testapp -m ./template.rb
=> datevalidatorとemailvalidatorがGemfileに追記された状態で作成される
Hamamatsu.rb 5
できること4 Gemfileの追記4 bundle install後に実行する処理の定義4 rails generateの実行4 shellコマンドの実行4 rakeタスクの実行4 routingの定義Hamamatsu.rb 6
解決できた課題4 よく使う開発用gemを忘れる4 bundleしたgemの初期化コマンドを忘れる4 "rspec:install" とか "bundle binstubs rspec-core"
4 タイムゾーンの設定を忘れる4 config.generators.test_frameworkの設定を忘れる
Hamamatsu.rb 7
template.rbgem_group :development, :test do gem "better_errors" gem "binding_of_caller" gem "pry-byebug" gem "pry-doc" gem "bullet" gem "awesome_print" gem "yard" gem "letter_opener" gem "letter_opener_web" gem "hirb" gem "hirb-unicode" gem "rubocop" gem "rubocop-rspec"end
Hamamatsu.rb 8
template.rbenvironment <<-EOF config.generators do |g| g.orm :active_record g.helper false g.assets false g.test_framework :rspec g.controller_specs true g.helper_specs true g.view_specs false g.fixture_replacement :factory_girl, dir: "spec/support/factories" endEOF
Hamamatsu.rb 9
template.rb
environment <<-EOF config.time_zone = "Tokyo" config.i18n.load_path += Dir[Rails.root.join("config", "locales", "**", "*.{rb, yml}").to_s] config.i18n.default_locale = :jaEOF
Hamamatsu.rb 10
template.rb
after_bundle do run("bundle install --path .bundle --jobs=4")
# initialize rspec run("bin/rails generate rspec:install") run("bin/bundle binstubs rspec-core")
# run rubocop run("bin/bundle exec rubocop --auto-correct --auto-gen-config")
# run spec run("bin/rspec")end
Hamamatsu.rb 11
実行rails new testapp -m ./template.rb --skip-bundle --skip-test
Hamamatsu.rb 12
その他4 environmentでコードを書き込むとインデントが少し崩れるので、"rubocop --auto-correct"で整形している
Hamamatsu.rb 13
4 Railsガイド4 https://gist.github.com/jacoyutorius/287be5b7a99825ed89c1a054e0aca872
Hamamatsu.rb 15
Recommended