2018/02/15分のコミットです。
CHANGELOGにのったコミットは以下の通りです。
Don't force people to upgrade i18n gem
activesupport/activesupport.gemspec
の修正です。
Bump i18n to 1.0でi18n gemを更新した際、バージョン1系を強制するようになっていたのですが、0.x系も使用できるよう、バージョン指定を緩めています。
Rdoc formatting fix: b instead of MD-style asterisks
activerecord/lib/active_record/relation.rb
のdocの修正です。
find_or_create_by
のdocでフォーマットが崩れていた箇所があったのを修正しています。
Merge pull request #30941 from toptal/introduce-custom-serializers-to-activejob-arguments
Active Jobの修正です。
jobの引数に任意のオブジェクトを渡せるようにするための仕組みを追加しています。
元々はRails側で管理されているクラス(String、Active Recordのmodel、HashWithIndifferentAccess等々)のオブジェクトしかjobの引数にしか渡せませんでした。ただ、ユーザが作成した独自のクラスのオブジェクト渡せないのは不便だろう、という事で、独自のクラスのオブジェクトも渡せるようになりました。
独自のクラスのオブジェクトを渡したい場合、そのオブジェクトのserialize / deserialize処理を定義した独自のserializerクラスを作る必要があります。
例。
class MoneySerializer < ActiveJob::Serializers::ObjectSerializer # Check if this object should be serialized using this serializer. def serialize?(argument) argument.is_a? Money end # Convert an object to a simpler representative using supported object types. # The recommended representative is a Hash with a specific key. Keys can be of basic types only. # You should call `super` to add the custom serializer type to the hash def serialize(object) super( "cents" => object.cents, "currency" => object.currency ) end # Convert serialized value into a proper object def deserialize(hash) Money.new hash["cents"], hash["currency"] end end
上記のように作成した serializerクラスを、Rails.application.config.active_job.custom_serializers << MoneySerializer
として、custom_serializers
に追加すればOKです(今ちょっと挙動バグっているようですが)。
Use require_dependency inside Active Storage
activestorage/app/models/active_storage/blob.rb
、
activestorage/app/models/active_storage/filename.rb
の修正です。
Active Storage内部で使用しているクラスをロードするのにrequire_dependency
を使用してファイルを明示的に指定するよう修正しています。
同じ名前のクラスがアプリやgemにあった場合に、そちらのクラスが読み込まれてしまう事がある為。
Merge pull request #31866 from fatkodima/redis_cache-connection_pool
Active Supportの修正です。
再度redis cache storeにconnection poolingのサポートを追加しています。
driverにRedis::Distributedを指定した場合に正しく動作しないバグがあった為、Revert "Merge pull request #31447 from fatkodima/redis_cache-connection_pool"でrevertされていましたが、左記バグの対応が完了した為。
Add #create_or_find_by to lean on unique constraints (#31989)
activerecord/lib/active_record/querying.rb
、
activerecord/lib/active_record/relation.rb
の修正です。
ActiveRecord::Relation
にcreate_or_find_by
メソッド、及び、create_or_find_by!
メソッドを追加しています。名前の通り、左記にcreate
してレコードが既にある場合(ActiveRecord::RecordNotUnique
でエラーになった場合)にfind
を実行するメソッドです。
def create_or_find_by(attributes, &block) transaction(requires_new: true) { create(attributes, &block) } rescue ActiveRecord::RecordNotUnique find_by!(attributes) end
find_or_create_by
だとfind(select)'と
create(insert)`の間にレコードが追加されてしまった場合にエラーになってしまうので、そのようなケースを避ける為に追加されています。
Missing backquote, extra end keyword [ci skip]
rails guideのActive Job Basics
の修正です。
Supported types for arguments
の項でクォートが不足していたのを修正、及び、Serializers
の項のexampleコードで不要なend
があったのを削除しています。