15
Rails Applica tion T emplate Hamamatsu.rb @jacoyutorius Hamamatsu.rb 1

Rails application template

Embed Size (px)

Citation preview

Page 1: Rails application template

Rails Application TemplateHamamatsu.rb

@jacoyutorius

Hamamatsu.rb 1

Page 2: Rails application template

yuto ogi

4 @jacoyutorius

4 ruby, javascript

4 Hamamatsu.rb, JAWS-UG Hamamatsu

4 FOURIER.Inc

Hamamatsu.rb 2

Page 3: Rails application template

Application Template

4 Railsの初期設定を定義するDSL

4 rails new時に実行

Hamamatsu.rb 3

Page 4: Rails application template

sample

template.rb

gem "date_validator"gem "email_validator"

Hamamatsu.rb 4

Page 5: Rails application template

sample

rails new testapp -m ./template.rb

=> datevalidatorとemailvalidatorがGemfileに追記された状態で作成される

Hamamatsu.rb 5

Page 6: Rails application template

できること4 Gemfileの追記4 bundle install後に実行する処理の定義4 rails generateの実行4 shellコマンドの実行4 rakeタスクの実行4 routingの定義Hamamatsu.rb 6

Page 7: Rails application template

解決できた課題4 よく使う開発用gemを忘れる4 bundleしたgemの初期化コマンドを忘れる4 "rspec:install" とか "bundle binstubs rspec-core"

4 タイムゾーンの設定を忘れる4 config.generators.test_frameworkの設定を忘れる

Hamamatsu.rb 7

Page 8: Rails application template

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

Page 9: Rails application template

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

Page 10: Rails application template

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

Page 11: Rails application template

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

Page 12: Rails application template

実行rails new testapp -m ./template.rb --skip-bundle --skip-test

Hamamatsu.rb 12

Page 13: Rails application template

その他4 environmentでコードを書き込むとインデントが少し崩れるので、"rubocop --auto-correct"で整形している

Hamamatsu.rb 13

Page 14: Rails application template

まとめ4 rails composerというのもある4 railscomposer.com

Hamamatsu.rb 14