2023/03/06分のコミットです。
CHANGELOGにのったコミットは以下の通りです。
- Autoloading setup honors root directories manually set by the user.
- Add
Object#with
to set and restore public attributes around a block
Improve support for custom namespaces
railties/lib/rails/application/bootstrap.rb
、
railties/lib/rails/application/finisher.rb
の修正です。
autoloadingでディレクトリに対してい独自の名前空間の設定を行えるよう修正しています。例えば、app/services
配下にあるclass/moduleをすべてServices
namespace配下に定義したい場合、app/services/services
というディレクトリを作成しその配下にファイルを格納する必要がありましたが、app/services/
配下に直接Services
namespace配下のファイルを定義できるようになっています。この場合、下記のようなinitializerを作成すれば良いようになっています。
# config/initializers/autoloading.rb module Services; end Rails.autoloaders.main.push_dir("#{Rails.root}/app/services", namespace: Services)
Merge pull request #47328 from zzak/horo-canonical-url
railties/lib/rails/api/task.rb
の修正です。
API docにcanonicalタグを設定するよう修正しています。
Active Supportの修正です。
指定されたblockの中でのみattributeの値を変更出来るようにする為のObject#with
メソッドを追加しています。
client.timeout # => 5 client.with(timeout: 1) do client.timeout # => 1 end client.timeout # => 5
よくテストで一時的にattributeの値を変更し、後処理でそれを元に戻す、という事をするのですが、#with
メソッドを使うことでそれを簡単に記載出来るようになっています。
def test_something_when_enabled some_call_that_may_raise enabled_was, SomeLibrary.enabled = SomeLibrary.enabled, true # test things ensure SomeLibrary.enabled = enabled_was end
上記のようなテストの場合、Object#with
を使用すると下記のように出来ます。
def test_something_when_enabled SomeLibrary.with(enabled: true) do # test things end end
Merge pull request #47552 from lsylvester/where-include-index
Active Recordの修正です。
index作成時に、PostgreSQLのINCLUDE
パラメータとWHERE
パラメータを一緒に指定すると不正なSQLが生成されてしまいエラーになってしまうバグがあったのを修正しています。
Edits in example code and railties CHANGELOG
rails guideのAutoloading and Reloading Constants
、及び、railties/CHANGELOG.md
の修正です。
autoloadingで名前空間を設定する場合のexampleで、引数の指定方法が誤っていたのを修正しています。