@Konboi memo

主に技術に関してつらつらと。

初回だけじゃない rails application template

最近rails書いてないですがrailsネタを。

はじめに

ご存知の人もいるかと思いますが、 rails template は初回だけじゃなくても適用できます。

実行環境

今回の実行環境は

です。

やってみる

今回はサンプル用に

Konboi/rails-template-sample の add_rspec_sample を使います。

templateの書き方は別途調べてください。

(rspec以外にもsimplecov追加して名前以上の振る舞いをしていて良くないとかは置いておきます。)

該当のrails applicationのディレクトリに移動します

./bin/rake rails:template LOCATION=https://raw.githubusercontent.com/Konboi/rails-template-sample/master/add_rspec_sample.rb

と入力します。

すると

         run  echo Added gem file from "."
Added gem file
     gemfile  group :development
      append  Gemfile
     gemfile  rspec-rails
     gemfile  rails-erd
      append  Gemfile
     gemfile  group :test
      append  Gemfile
     gemfile  simplecov
     gemfile  simplecov-rcov
      append  Gemfile
         run  ./bin/rails g rspec:install from "."
        from ./bin/rails:4:in `<main>'
         run  rm -rf test from "."

実行されます。

$ git st                                                                                                                                                                                                  [/Users/yabuki-ryosuke/project/fonta-app]
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   Gemfile
        modified:   Gemfile.lock
        deleted:    test/controllers/.keep
        deleted:    test/fixtures/.keep
        deleted:    test/helpers/.keep
        deleted:    test/integration/.keep
        deleted:    test/mailers/.keep
        deleted:    test/models/.keep
        deleted:    test/test_helper.rb

こんな感じの差分ができ問題なく実行されているのがわかります。

ちなみに こちらを使うとtestというファイルが新規で作成されるので簡単に試せます。

まとめ

  • RailsApps/rails-composer のように1枚に書くのもいいですが、 1個1個必要な物を細かく書いたほうがメンテナンスも楽なので分けて使うことをオススメします。

  • チームでよく使うのをまとめておくと捗るかもしれません。

あわせて読みたい

#12 Railsの面倒な初期設定を自動化するApplication Templates

パーフェクト Ruby on Rails

パーフェクト Ruby on Rails