なるようになるブログ

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

rails commit log流し読み(2017/11/29)

2017/11/29分のコミットです。

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

actionpack/CHANGELOG.md

activerecord/CHANGELOG.md

actionview/CHANGELOG.md


Fix optimized url helpers when using relative url root

actionpack/lib/action_dispatch/routing/route_set.rbの修正です。

relative url rootを指定している場合に、url helperが正しいpathを返さなかった(relative url rootの指定を考慮した値が返ってなかった)のを修正しています。


Fix typos and add a few suggestions

各READMEファイルのグラマーの修正を行っています。


Preparing for 5.2.0.beta2 release

5.2.0.beta2のリリース準備として、各コンポーネントのバージョンを5.2.0-beta1に更新、CHANGELOGの先頭にリリース日を記載、等を行っています。

なお、beta1からの差分は、Active Storage(gemにmigrations filesを含むのを忘れていた対応)だけです。


Make sure the request exist befoe trying to send early hints

actionview/lib/action_view/helpers/asset_tag_helper.rbの修正です。

javascript_include_tagstylesheet_link_tagメソッドで、early hintsを送信する際に、requestオブジェクトが存在するかチェックするよう修正しています。

Action Mailerだとrespond_to?(:request)がtrueになるが、requestオブジェクトが存在しない、という状態になる為。


Merge pull request #31254 from suginoy/update_doc_find_order

activerecord/lib/active_record/relation/finder_methods.rbのdocの修正です。

ActiveRecord::FinderMethods#findメソッドのdocに、引数のidを配列で指定した場合、結果はそのid順にはならないだろう、と記載されていたのですが、実際はid順になる(ActiveRecord::Base#find(array) returning result in the same order as the array passed)為、その旨説明を修正、及び、DBでソートされた結果が欲しい場合、whereメソッドを使うよう説明を追加しています。


Merge pull request #31179 from kinnrot/scoping-reserved-names

activerecord/lib/active_record/enum.rbactiverecord/lib/active_record/scoping/named.rbの修正です。

enumで、Relationインスタンスメソッドと同名のscope(e.g. recordsto_ary)を定義出来ないよう修正しています。同じ名前が使われた場合、ArgumentErrorがraiseされます。


Formatting fix for example code

activesupport/lib/active_support/deprecation/constant_accessor.rbactivesupport/lib/active_support/deprecation/proxy_wrappers.rbのdocの修正です。

DeprecatedConstantAccessor module及びDeprecatedConstantProxy classのdocのexampleコード内のコメント部分の先頭に#を追加しています。


Merge pull request #31268 from tjschuck/refactor_prev_next_occurring

activesupport/lib/active_support/core_ext/date_and_time/calculations.rbの修正です。

next_occurring及びprev_occurringメソッドで時間を移動するのにsince / agoメソッドを使用していたのを、advanceを使用するよう修正しています。

メソッドの結果が、呼び出し元と同じクラスのインスタンスになるようにする為。

# Before
today = Date.today
# => Wed, 29 Nov 2017
today.class
# => Date
today.next_occurring(:wednesday)
# => Wed, 06 Dec 2017 00:00:00 UTC +00:00
today.next_occurring(:wednesday).class
# => ActiveSupport::TimeWithZone


# After
today = Date.today
# => Wed, 29 Nov 2017
today.class
# => Date
today.next_occurring(:wednesday)
# => Wed, 06 Dec 2017
today.next_occurring(:wednesday).class
# => Date

[ci skip] Correct output for Upcase

activesupport/lib/active_support/core_ext/string/multibyte.rbのdocの修正です。

String#mb_charsメソッドのdoc内の"lj".upcaseの実行結果が実際の結果と異なっていたのを修正しています。

が、これは元の結果が正しい(正確にはUnicode case mappingsがサポートされたRuby 2.4以降とそれより前で結果が違う)為、後ほど再度修正されています。


Merge pull request #31251 from rails/preload_link_tag

二つの対応が一つのPRで行われており、ひとつ目はよく使われる audio/video/fontのmime types(video/webmfont/ttfaudio/aac等)をデフォルトのmime typeに追加しています。

もうひとつは、リソースのローディングを最適化する為のPreloadを使用する為のpreload_link_tagメソッドです。

preload_link_tagの実行例は下記の通り。

preload_link_tag("custom_theme.css")
# => <link rel="preload" href="/assets/custom_theme.css" as="style" type="text/css" />

preload_link_tag("/videos/video.webm")
# => <link rel="preload" href="/videos/video.mp4" as="video" type="video/webm" />

preload_link_tag(post_path(format: :json), as: "fetch")
# => <link rel="preload" href="/posts.json" as="fetch" type="application/json" />

preload_link_tag("worker.js", as: "worker")
# => <link rel="preload" href="/assets/worker.js" as="worker" type="text/javascript" />

preload_link_tag("//example.com/font.woff2")
# => <link rel="preload" href="//example.com/font.woff2" as="font" type="font/woff2" crossorigin="anonymous"/>

preload_link_tag("//example.com/font.woff2", crossorigin: "use-credentials")
# => <link rel="preload" href="//example.com/font.woff2" as="font" type="font/woff2" crossorigin="use-credentials" />

preload_link_tag("/media/audio.ogg", nopush: true)
# => <link rel="preload" href="/media/audio.ogg" as="audio" type="audio/ogg" />

mime typeに合わせて適切なas属性を出力してくれるようになっています。また、デフォルトでearly hintsを送信するようになっています。

参考:


Register "audio/mp4" mime type with :m4a symbol

actionpack/lib/action_dispatch/http/mime_types.rbの修正です。

mime typeのsymbolとしてmp4が複数登録されていたので、audio/mp4の方のsymbolをm4aに変更しています。


Restore mpeg mime type, delete less common mime types

actionpack/lib/action_dispatch/http/mime_types.rbの修正です。

Merge pull request #31251 from rails/preload_link_tagで追加されたmime typeのうち、あまりまだ一般的ではないと思われるmime type(application/ogxaudio/mpeg等)を削除しています。

一度Rails本体に入れてしまうととずっとそのmime typeをメンテする必要がある為、そんなに使われてないmime typeまで本体に入れる必要は無いだろう、という事で削除されています。


Fix typo in mime type registering

actionpack/lib/action_dispatch/http/mime_types.rbの修正です。

mime typeの登録処理でパーセント記法をタイポしている箇所があったのを修正しています。


Fix tests: Remove ogx mime type from tests

actionpack/test/dispatch/mime_type_test.rbの修正です。

Restore mpeg mime type, delete less common mime typesの修正の影響で壊れたテストがあったのを修正しています。


Mention about Ruby 2.4 Unicode case mappings in mb_chars example [ci skip] (#31275)

activesupport/lib/active_support/core_ext/string/multibyte.rbのdocの修正です。

[ci skip] Correct output for Upcaseをrevert、及び、String#mb_charsメソッドのdocに、Ruby 2.4より前のバージョンで有効なexampleである旨説明を追加しています。


Merge pull request #31272 from y-yagi/use_credentials_instead_of_keyfile_in_gcs

activestorage/lib/active_storage/service/gcs_service.rbrailties/lib/rails/generators/rails/app/templates/config/storage.yml.ttの修正です

Active StorageでGoogle Cloud Storageを使用する際、アカウントキーを指定するキーワードにkeyfileを使用していたのを、credentialsを使用するよう修正しています。

-#   keyfile: <%%= Rails.root.join("path/to/gcs.keyfile") %>
+#   credentials: <%%= Rails.root.join("path/to/gcs.keyfile") %>

google-cloud-storage 1.8.0からcredentialsが使用するのが推奨されるようになった為。

参考:Consider using credentials instead of keyfile