Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Rails application template

1,157 views

Published on

Hamamatsu.rb#78でのLT資料です。
Ruby on RailsのApplication Template機能について。

Published in: Software
  • Be the first to comment

  • Be the first to like this

Rails application template

  1. 1. Rails Application Template Hamamatsu.rb @jacoyutorius Hamamatsu.rb 1
  2. 2. yuto ogi 4 @jacoyutorius 4 ruby, javascript 4 Hamamatsu.rb, JAWS-UG Hamamatsu 4 FOURIER.Inc Hamamatsu.rb 2
  3. 3. Application Template 4 Railsの初期設定を定義するDSL 4 rails new時に実行 Hamamatsu.rb 3
  4. 4. sample template.rb gem "date_validator" gem "email_validator" Hamamatsu.rb 4
  5. 5. sample rails new testapp -m ./template.rb => datevalidatorとemailvalidatorがGemfileに追記された 状態で作成される Hamamatsu.rb 5
  6. 6. できること 4 Gemfileの追記 4 bundle install後に実行する処理の定義 4 rails generateの実行 4 shellコマンドの実行 4 rakeタスクの実行 4 routingの定義 Hamamatsu.rb 6
  7. 7. 解決できた課題 4 よく使う開発用gemを忘れる 4 bundleしたgemの初期化コマンドを忘れる 4 "rspec:install" とか "bundle binstubs rspec-core" 4 タイムゾーンの設定を忘れる 4 config.generators.test_frameworkの設定を忘れる Hamamatsu.rb 7
  8. 8. template.rb gem_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
  9. 9. template.rb environment <<-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" end EOF Hamamatsu.rb 9
  10. 10. 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 = :ja EOF Hamamatsu.rb 10
  11. 11. 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
  12. 12. 実行 rails new testapp -m ./template.rb --skip-bundle --skip-test Hamamatsu.rb 12
  13. 13. その他 4 environmentでコードを書き込むとインデントが少し崩れ るので、 "rubocop --auto-correct"で整形している Hamamatsu.rb 13
  14. 14. まとめ 4 rails composerというのもある 4 railscomposer.com Hamamatsu.rb 14
  15. 15. 4 Railsガイド 4 https://gist.github.com/jacoyutorius/ 287be5b7a99825ed89c1a054e0aca872 Hamamatsu.rb 15

×