なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2018/04/03)

2018/04/03分のコミットです。

CHANGELOGにのったコミットは以下の通りです。

actionview/CHANGELOG.md


Merge pull request #32404 from mathieumahe/master

actionview/app/assets/javascripts/rails-ujs/features/confirm.coffeeの修正です。

ユーザが独自のconfirm処理を使用出来るようにする為に、confirm dialogを表示する処理をfunction(Rails.confirm)に切り出しています。


Merge pull request #32336 from vincedevendra/allow_mutating_dig_return_value

actionpack/lib/action_controller/metal/strong_parameters.rbの修正です。

ActionController::Parameters#digの戻り値がActionController::Parametersインスタンスだった場合に、毎回新しいオブジェクトを生成していたのを、digを呼び出した自身を返すよう修正しています。

毎回新しいオブジェクトが生成されると、digの結果に直接値を指定する事ができない為、との事です。

# before
params = ActionController::Parameters.new(a: { b: { c: 1 } })
params.dig(:a, :b)[:c] = 2
params # => <ActionController::Parameters {"a"=>{"b"=>{"c"=>1}}} permitted: false>

params = ActionController::Parameters.new(a: { b: [1] })
params.dig(:a, :b)[0] = 2
params # => <ActionController::Parameters {"a"=>{"b"=>[1]}} permitted: false>


# after
params = ActionController::Parameters.new(a: { b: { c: 1 } })
params.dig(:a, :b)[:c] = 2
params # => <ActionController::Parameters {"a"=><ActionController::Parameters {"b"=><ActionController::Parameters {"c"=>2} permitted: false>} permitted: false>} permitted: false>

params = ActionController::Parameters.new(a: { b: [1] })
params.dig(:a, :b)[0] = 2
params # => <ActionController::Parameters {"a"=><ActionController::Parameters {"b"=>[2]} permitted: false>} permitted: false>

Add action_view.finalize_compiled_template_methods config option

Action Viewの修正です。

ActionView::Templateのfinalizerを実行するかどうかを指定するためのconfig(action_view.finalize_compiled_template_methods)を追加しています。デフォルトはtest envではfalse(environments/test.rbで指定)、他の環境ではtrueです。

Template::compileメソッドでは、ObjectSpace#define_finalizerを使用して、ActionView::CompiledTemplatesのオブジェクトが解放される際に定義されているメソッドを削除するようにしています。

これは頻繁にtemplateを更新するであろうdevelopment envでcompiled templatesがleakするのを防ぐ為らしいのですが、templateを更新しないtest envではこの処理はそもそも不要、かつ、templateが大量にある環境だとメソッドの削除処理のコストが高い為(テスト実行時間に影響があるレベルらしい)、finalizerを実行しないように出来るよう、configを追加したとの事です。


Small doc fixes

docの修正です。

各docのフォーマット、不要なスペースの削除等を行っています。


Doc fix added missing quote

actionmailer/lib/action_mailer/test_helper.rbのdocの修正です。

assert_enqueued_emailsメソッドのdoc内のexampleコードでクォートが不足している箇所があったのを修正しています。


Remove credits.html from Rails Guides

Rails guideからcreditsページを削除しています。

guideの初期の頃に携わって人達が記載されていたのですが、ページ自体が保守されていない、かつ、今はRails Contributorsがあるので、個別ページはいらないだろう、というような理由で削除されています。


Display db:drop description in ActiveRecord

activerecord/Rakefileの修正です。

db:drop taskにdescを追加しています。


Cleanup credits related code as it is removed now in PR #32429

guides/rails_guides/helpers.rbguides/rails_guides/kindle.rbの修正です。

creditsページ作成に関する処理が残っていたのを削除しています。