なるようになるブログ

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

rails commit log流し読み(2019/04/23)

2019/04/23分のコミットです。

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

railties/CHANGELOG.md


Allow sass-rails greater than 5.x in new apps

railties/lib/rails/generators/app_base.rbの修正です。

新規に作成したアプリケーションで、sas-railsのバージョン指定を緩めています(~> 5.0 -> ~> 5)


[ci skip] Active Storage: updating associations replaces

rails guideのRuby on Rails 6.0 Release Notesの修正です。

Active StorageのNotable changesの項に、attached modelに対するupdate / update!の挙動が、associationの追加から更新(既存のファイルの削除)に変更になった事について説明を追加しています。


Merge pull request #36038 from st0012/fix-35602

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

ActionController::APIでCaching moduleをincludeするよう修正しています。

が、API modeでview cacheがデフォルトで必要かというと、それは不要では無いか(使わないケースが多いのでは)という話になり直後にrevertされています。


Revert "Include Caching module for ActionController::API"

という訳で直前のCaching moduleに関する対応をrevertしています。


upgrades Zeitwerk to 2.1.4

Active Supportの修正です。

Zeitwerkのバージョンを2.1.4に修正しています。

合わせて、depend on Zeitwerk 2.1.0で削除したautoloaded_constants、及び、autoloaded?メソッドを戻しています。どちらもRailsガイドに説明が記載されているメソッドな為。


Implements the task zeitwerk:check

railties/lib/rails/tasks/zeitwerk.rakeの修正です。

アプリの構成が新しいautoloader(Zeitwerkを使用したloader)で使用出来るかどうかをチェックする為のzeitwerk:check taskを追加しています。

元のautoloaderと新しいautoloaderはちょいちょい挙動が違う箇所があり、このtaskを使うと新しいautoloaderが使用出来るか、出来ない場合は何が問題なのかを表示してくれるようになっています。


Merge pull request #36029 from kamipo/deprecate_where_not

Active Recordの修正です。

where.notがNORとして動作していたのがdeprecateになりました。Rails 6.1ではNANDとして動作するようになります。

User.where.not(name: "bob", role: "admin")
# => DEPRECATION WARNING: NOT conditions will no longer behave as NOR in Rails 6.1. To continue using NOR conditions, NOT each conditions manually (`.where.not(:name => ...).where.not(:role => ...)`).

メッセージに出ている通り、引き続きNORとして使用したい場合、条件を別に指定する必要があります。 NORだとpolymorphic associationに対するが期待通りに動作しない(where.not(polymorphic_type: object.class.polymorphic_name, polymorphic_id: object.id)だと期待する結果にならない)為。


Add PR link for Active Storage updating release note entry [ci skip]

rails guideのRuby on Rails 6.0 Release Notesの修正です。

Active StorageのNotable changesの項にある説明に、PRへのリンクを追加しています。


Merge pull request #36057 from jhawthorn/activejob_retry_logic

activejob/lib/active_job/exceptions.rbの修正です。

retry_onメソッドでexception_executions(exception毎のretry回数を保持する変数)が定義されていない場合に、Hash.new(0)exception_executionsを初期化していたのを、値を初期化するのではなくグローバルの実行数を使用するよう修正しています。

Rails 6.0から、exception毎のretry回数を保持するようになりました(Keep executions for each specific exception)。ただ、Rails 6より前に格納されたjobでは、retry回数を保持していない為、Support in-flight jobs stored before individual execution counters for retry_on (#34731)exception_executionsが定義されていない場合値を初期化するようにしました。

しかし、これだとRails 6とRails 5.2のアプリが混在にしている時に正しくリトライが行えないという問題が発生してしまっていました(Rails 6側のアプリでexception_executionsを初期化しても、Rails 5.2のアプリではその変数を扱えない為リトライ数が正しく管理出来てなかった)。

そのため、exception_executionsが定義されていない場合は、Rails 5.2の時と同様にグローバルの実行数を使用するようにしています。


Merge pull request #36060 from st0012/fix-35602-doc

rails guideのUsing Rails for API-only Applicationsの修正です。

Adding Other Modulesの項に、view Cachingを使用したい場合の設定方法についての説明を追加しています。


Merge pull request #36059 from composerinteralia/model-attribute-names

activemodel/lib/active_model/attributes.rbの修正です。

ActiveModel::Attributes#attribute_names.attribute_namesメソッドを追加しています。名前の通り、attributeの名前の配列を返すメソッドです。

class Person
  include ActiveModel::Attributes

  attribute :name, :string
  attribute :age, :integer
end

Person.attribute_names
# => ["name", "age"]