なるようになるブログ

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

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

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

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

activerecord/CHANGELOG.md

activesupport/CHANGELOG.md


Introduce ActiveStorage::Attached::{One,Many}#detach

activestorage/lib/active_storage/attached/many.rbactivestorage/lib/active_storage/attached/one.rbの修正です。

blobはそのままでattachementだけを削除する、ActiveStorage::Attached::One#detach及びAttached#Many#detachメソッドを追加しています。

attachementのリプレイス処理で使う為のようです。それ以外でも使うのかなあ。


CI against JRuby 9.1.14.0

.travis.ymlの修正です。

CIで使用するJRubyのバージョンを9.1.14.0に更新しています。


Add a #populate method to migrations (#31082)

activerecord/lib/active_record/migration.rbの修正です。

migrationにupのときだけ使用出来るup_onlyメソッドを追加しています。

class AddPublishedToPosts < ActiveRecord::Migration[5.3]
  def change
    add_column :posts, :published, :boolean, default: false
    up_only do
      execute "update posts set published = 'true'"
    end
  end
end

上記のような感じで、カラムの追加をした時だけ何かを行う、という場合に使うことを想定しるようです


Merge pull request #30963 from q-centrix/performance-improvements-add_method_to_attributes

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

UrlHelper#add_method_to_attributes!でhttp methodがgetかどうかを判定する為に毎回String#to_s + String#downcaseを呼び出していたのを、methodのHashを保持し、それとマッチするかどうかチェックするよう修正しています。

-          if method && method.to_s.downcase != "get" && html_options["rel"] !~ /nofollow/
+          if method_not_get_method?(method) && html_options["rel"] !~ /nofollow/
             if html_options["rel"].blank?
               html_options["rel"] = "nofollow"
             else
@@ -599,6 +599,19 @@ def add_method_to_attributes!(html_options, method)
           html_options["data-method"] = method
         end

+        STRINGIFIED_COMMON_METHODS = {
+          get:    "get",
+          delete: "delete",
+          patch:  "patch",
+          post:   "post",
+          put:    "put",
+        }.freeze
+
+        def method_not_get_method?(method)
+          return false unless method
+          (STRINGIFIED_COMMON_METHODS[method] || method.to_s.downcase) != "get"
+        end

これで(STRINGIFIED_COMMON_METHODSに一致するケースであれば)不要なString objectの生成が減るので、ちょっと性能改善になっている、との事です。


Use released arel

GemfileGemfile.lockの修正です。

arelを使用するのにGitHubのmaterブランチを直接指定していたのを、リリース済みのgemを使用するよう修正しています。arel 9.0がリリースされた為、


Use released sass-rails

GemfileGemfile.lockの修正です。

sass-railsを使用するのにGitHubを直接指定していたのを、リリース済みのgemを使用するよう修正しています。


Fix migration version in doc of #up_only

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

up_onlyメソッドのdoc内のexampleコードで、migration versionが5.3になっていたのを5.2に修正しています。


Fix activesupport/CHANGELOG.md [ci skip]

activesupport/CHANGELOG.mdの修正です。

Redis cache storeのサポートを追加した対応のエントリーのフォーマットを修正しています。


Merge pull request #30004 from npenzin/patch-1

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

rails plugin作成時のディレクトリがrails application配下だった場合、自動でrails applicationのGemfileにそのpluginを追加するのですが、その際に先頭に改行を追加するよう修正しています。

-        entry = "gem '#{name}', path: '#{relative_path}'"
+        entry = "\ngem '#{name}', path: '#{relative_path}'"

元のGemfileの終端が空行じゃなかった場合に、Gemfileのフォーマットが崩れてしまう為。


Fix typo s/only_up/up_only/ [ci skip]

activerecord/CHANGELOG.mdの修正です。

up_onlyonly_upにタイポしていたのを修正しています。


Fix CI failure due to invalid up_only for MySQL

activerecord/test/cases/invertible_migration_test.rbの修正です。

up_onlyメソッドのテストがMySQLで通ってなかったのを修正しています。


Fix asset url examples [ci skip]

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

javascript_urlstylesheet_urlメソッド等assets url helperのdoc内のexampleの実行結果が、実際の結果と異なっていたのを修正しています。


Update configuring.md

rails guideのConfiguring Rails Applicationsの修正です。

Using Initializer Filesの項で、initializer間に依存がある場合に、アルファベット順にロードされる事を利用してファイル名を調整する(e.g. 01_critical.rb等)事を推奨していたのを、依存関係があるコードは同じファイルに記載するよう修正しています。

ファイル名の変更を減らせるのと、その方が依存関係がわかりやすい為、との事です。


Use released arel

bug report templatesの修正です。

リリース済みのarelを使用するよう修正しています。


These strings should already be frozen where ruby accepts the magic-comment

activesupport/test/core_ext/object/instance_variables_test.rbの修正です。

instance_execのテストで、Stringをdupした値を使用するよう修正しています。

  def test_instance_exec_passes_arguments_to_block
-    assert_equal %w(hello goodbye), "hello".instance_exec("goodbye") { |v| [self, v] }
+    assert_equal %w(hello goodbye), "hello".dup.instance_exec("goodbye") { |v| [self, v] }
   end

Stringがfrozenされた時の為の対応という風にコミットログからは読み取れるのですが、この場合、オブジェクト自身を変える訳では無いのでdup無くても大丈夫そうな気が…。


Handle TZInfo::AmbiguousTime errors

activesupport/lib/active_support/values/time_zone.rbの修正です。

Europe/Moscowのようにタイムゾーンが複数ある値を指定した場合に、TZInfo::AmbiguousTimeが発生していたのを、発生しないよう修正しています。

# before
"2014-10-26 01:00:00".in_time_zone("Moscow")
# => TZInfo::AmbiguousTime: 26/10/2014 01:00 is an ambiguous local time.

# after
"2014-10-26 01:00:00".in_time_zone("Moscow")
# => Sun, 26 Oct 2014 01:00:00 MSK +03:00

Rubyの挙動(後の期間を使用する)と合わせる為。


Merge pull request #29776 from mrj/fix-idlw-timezone

activesupport/lib/active_support/values/time_zone.rbの修正です。

International Date Line West timezoneの値が誤っていたのを修正しています。