なるようになるブログ

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

rails commit log流し読み(2016/11/30)

2016/11/30分のコミットです。

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

railties/CHANGELOG.md

activerecord/CHANGELOG.md


Merge pull request #26836 from Liceth/npm

railtiesの修正です。

rails newコマンドに--yarnオプションを追加しています。

--yarnオプションつけてrailsアプリを生成した場合、package.jsonの生成、Rails.application.config.assets.pathsnode_modulesを追加、等が行われた状態でアプリが生成されるようになっています。


Add CHANGELOG entry for --yarn option

railties/CHANGELOG.mdの修正です。

先のyarnの対応についてCHANGELOGにentryを追加しています。


Let's use only vendored rails-ujs while we start to publish it to npm registry

railties/lib/rails/generators/rails/app/templates/package.jsonの修正です。

デフォルトで生成されるpackage.jsonからrails-ujsを削除しています。rails-ujsの実装がAction Viewに含まれた為、別途packageとして入れる必要が無い為、ですかねえ。


Merge pull request #27126 from kamipo/fix_unsigned_with_zerofill

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rbactiverecord/lib/active_record/connection_adapters/mysql/column.rbの修正です。

zerofillを使用した場合に、unsigned型のカラムがsignedとして扱われてしまうバグがあったのを修正しています。

zerofillというもの自体を初めて知りました。参考:MySQL :: MySQL 5.6 リファレンスマニュアル :: 11.1.1 数値型の概要


Treat combined durations as a single unit

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

ActiveSupport::Duration同士の結合処理を行った場合に、partsの値を別々(duration毎の値をそのまま)に保持するようになっていたのを、一つに結合して保持するよう修正しています。

別々の保持してしまうと、結合処理を行ったDurationに対して更にTimeオブジェクト等の結合を行った場合に、結果が正しく取得出来ない事がある為、との事です。

# before

d1 = 3.months - 3.months
# => 0 months
d1.parts
# => [[:months, 3], [:months, -3]]
d2 = 2.months - 2.months
# => 0 months

time = Time.parse("Nov 29, 2016")
# => 2016-11-29 00:00:00 +0900
time + d1
# => 2016-11-28 00:00:00 +0900
time + d2
# => 2016-11-29 00:00:00 +0900
# after

d1 = 3.months - 3.months
# => 0 months
d1.parts
# => {:months=>0}
d2 = 2.months - 2.months
# => 0 months

time = Time.parse("Nov 29, 2016")
# => 2016-11-29 00:00:00 +0900
time + d1
# => 2016-11-29 00:00:00 +0900
time + d2
# => 2016-11-29 00:00:00 +0900

Document 'false' as option for 'action_on_unpermitted_parameters'

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

ActionController::Parametersクラスのdocのaction_on_unpermitted_parameters optionについて説明している箇所に、falseを指定した場合の挙動についての説明を追加しています。


Fix typo in Rails 5.0 release notes – “when when”

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

古いmysql gemのサポートを削除した対応についてのエントリーのタイポを修正しています。


Missing require 'active_support/notifications'

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

不足していたactive_support/notificationsのrequireを追加しています。


fix typo in changelog

railties/CHANGELOG.mdの修正です。

yarn対応についてのエントリーのタイポを修正しています。


removed @current as it is not used

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

Rails::Paths::Rootクラスから使用していない@current変数を削除しています。


Avoid race condition in AJ integration tests

activejob/test/support/integration/dummy_app_template.rbactivejob/test/support/integration/helper.rbの修正です。

Active Jobのintegration test用jobで、jobの結果を書き込むファイルの作成を、処理終了時に行うよう修正しています。

  def perform(x)
-    File.open(Rails.root.join("tmp/\#{x}"), "wb+") do |f|
+    File.open(Rails.root.join("tmp/\#{x}.new"), "wb+") do |f|
       f.write Marshal.dump({
         "locale" => I18n.locale.to_s || "en",
         "executed_at" => Time.now.to_r
       })
     end
+    File.rename(Rails.root.join("tmp/\#{x}.new"), Rails.root.join("tmp/\#{x}"))
   end

対象のファイルがあるかどうかでjobが終了したかどうかをチェックしており、最初にファイルを作成してしまうと、jobが終了してないにも関わらず、jobが終了している、と判断されてしまう可能性がある為、のようです。


use Gem.win_platform? to check windows Ruby platforms

Windows環境かどうかをチェックするのにGem.win_platform?メソッドを使用するよう修正しています。

元々はRbConfig::CONFIG["host_os"]を直接参照しチェックしていたのですが、チェックの仕方があまく漏れがあった為、正確にチェック出来るようする為にGem.win_platform?メソッドを使用するよう修正しています。


Prevent race condition when launching EventMachine reactor

actioncable/lib/action_cable/subscription_adapter/evented_redis.rbの修正です。

EventMachine reactorが起動済みかどうかチェックするのに、EventMachine.reactor_threadnilじゃないかどうかもチェックするよう修正しています。

        def ensure_reactor_running
-          return if EventMachine.reactor_running?
+          return if EventMachine.reactor_running? && EventMachine.reactor_thread
           @@mutex.synchronize do
             Thread.new { EventMachine.run } unless EventMachine.reactor_running?
-            Thread.pass until EventMachine.reactor_running?
+            Thread.pass until EventMachine.reactor_running? && EventMachine.reactor_thread
           end
         end

EventMachine.reactor_running?だけでは、実際に処理ループに入ってるかどうかはチェック出来ない為、initialize_event_machineがよばれた際にセットされるEventMachine.reactor_threadの値も見るようにしたとの事です。