なるようになるブログ

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

rails commit log流し読み(2017/09/18)

2017/09/18分のコミットです。

CHANGELOGへの追加はありませんでした。


Add missing round bracket in “Ruby on Rails 5.1 Release Notes” guide

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

“Deprecated passing string to :if and :unless conditional options on set_callback and skip_callback"の対応へのコミットのリンクに閉じ括弧が不足していたのを修正しています。


Remove useless condition in reset_association

activerecord/lib/active_record/associations/preloader/through_association.rbの修正です。

ThroughAssociation#reset_associationメソッドのresetすべきかどうかの判定処理から、不要なoptionのチェック処理を削除しています。

-            should_reset = (through_scope != through_reflection.klass.unscoped) ||
-               (options[:source_type] && through_reflection.collection?)
+            should_reset = through_scope != through_reflection.klass.unscoped

options[:source_type]が設定されている場合、必ずthrough_scopeが設定されており、through_scopeだけをチェックすれば良い為。


Return through_scope only if the scope is not empty scope

activerecord/lib/active_record/associations/preloader/through_association.rbの修正です。

ThroughAssociation#reset_associationメソッドでscopeがempty scopeじゃない場合のみ値を返すよう修正しています。empty scopeの場合scopeのmerge処理が不要な為。


Don’t pass reflection_scope to preload_scope if reflection.scope isn’t given

activerecord/lib/active_record/associations/preloader/through_association.rbの修正です。

ThroughAssociation#associated_records_by_ownerメソッドでreflection.scopenilの場合、不要なorderのmerge処理は行わないよう修正しています。


Early return if records.empty? in Preloader#preload

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

Preloader#preloadメソッドでrecordsが空の場合不要なArrayの生成処理を行わいよう修正しています。


Place class level update, destroy, and delete in Persistence::ClassMethods https://github.com/rails/rails/commit/9ac7dd47c5e847f7dbfb8d527ee2b917fa9fcd38

Active Recordの修正です。

activerecord::Relationクラスに定義されていたclass levelのupdatedestroydeleteメソッドをPersistenc::ClassMethodsに移動しています。

そもそもRelationに依存しているメソッドではないので、Persistence::ClassMethodsに定義されている方が適切な為との事です。


Ensure returning affected objects for class level update and destroy

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

class levetのupdatedestroyが更新・削除されたオブジェクトのみ返すよう修正しています。

      def update(id = :all, attributes)
         if id.is_a?(Array)
-          id.map.with_index { |one_id, idx| update(one_id, attributes[idx]) }
+          id.map.with_index { |one_id, idx| update(one_id, attributes[idx]) }.compact
         elsif id == :all
           all.each { |record| record.update(attributes) }
         else
@@ -112,6 +112,7 @@ def update(id = :all, attributes)
           object.update(attributes)
           object
         end
+      rescue RecordNotFound
       end

合わせて、RecordNotFoundをrescueするようにしています。これはupdatedestroyは内部的にfindを使用しており、不正なidが指定された場合にRecordNotFoundがraiseされてしまう事があるため。


id (primary key) is not only an integer [ci skip]

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

class levelのdestroyメソッドのdocに、引数のidに指定出来るのはIntegerまたはIntegerのArrayであるむね説明が記載されていたのですが、実際はidはIntegerとは限らない為、説明を修正しています。


Remove the code that swapping scope and options

activerecord/lib/active_record/associations.rbactiverecord/lib/active_record/associations/builder/association.rb

Association.create_reflectionメソッドでscope引数がHashだった場合、それをoptionsに設定していた処理があったのを削除しています。

scopeoptionsが設定される事があった為そのような処理にしていたようなのですが、現状そのような状態になる事はない為削除したようです。


Fix collided sequence name detection

activerecord/lib/active_record/connection_adapters/postgresql/column.rbの修正です。

sequence nameの検出処理に誤りがあり、sequence nameが衝突した場合にserialの判定が正しく行えないバグがあったのを修正しています。


Remove unused require in ActiveStorage::Variation

activestorage/app/models/active_storage/variation.rbの修正です。

使用していないactive_support/core_ext/object/inclusionのrequireを削除しています。


Extract associate_records_to_owner to refactor Preloader::Association

Active Recordの修正です。

Preloader::Association#preloadで行っていたassociationの関連付けをPreloader::Association#associate_records_to_ownerメソッドで行うようリファクタリングしています。

PreloaderPreloader::Associationにそれぞれpreloadメソッドがあるのがわかりずらいのと、preloadというメソッド名で中でassociated_records_by_ownerを呼んでいるのがわかりずらい為、上記のようなリファクタを行ったようです。


The name of the key on the owner is abstracted as reflection.join_foreign_key

Active Recordの修正です。

Preloader::Association#owner_key_nameメソッドでreflection.join_foreign_keyの結果を返すよう修正、及び、この対応により不要になったAssociationの子クラスのowner_key_nameメソッドを削除しています。


The name of the key on the associated record is abstracted as reflection.join_primary_key

Active Recordの修正です。

Preloader::Association#association_key_nameメソッドでreflection.join_primary_keyの結果を返すよう修正、及び、この対応により不要になったAssociationの子クラスのowner_key_nameメソッドを削除しています。


Remove unused delegation to reflection.options in Preloader::Association

activerecord/lib/active_record/associations/preloader/association.rbactiverecord/lib/active_record/associations/preloader/through_association.rbの修正です。

使用していないPreloader::Association#optionsメソッドを削除しています。


Merge pull request #26707 from jcoleman/add_attribute_names_cache_busting_spec

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

Model.columnsの値が変わった時にModel.attribute_namesのキャッシュが破棄される事を確認するテストを追加しています。


Remove “the” [ci skip]

rails guideのRuby on Rails Security Guideの修正です。

Custom credentialsの項のグラマーの修正を行っています。


Upcase js [ci skip]

rails guideのCaching with Rails: An Overviewの修正です。

Javascript -> JavaScriptに修正しています。


Fix quotes [ci skip]

docの修正です。

“’” -> “‘” に修正しています。


add section to guides for discarding and retrying active jobs [ci skip]

rails guideのActive Job Basicsの修正です。

Retrying or Discarding failed jobsの項を追加し、retry_on及びdiscard_onを使用した場合のexampleコードを追加しています。


Use ApplicationJob instead of ActiveJob::Base in guide [ci skip]

rails guideのActive Job Basicsの修正です。

exampleコードの親クラスをActiveJob::BaseからApplicationJobに修正しています。