なるようになるブログ

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

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

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

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

activesupport/CHANGELOG.md

activerecord/CHANGELOG.md


Add additional options to time change methods

activesupport/lib/active_support/core_ext/time/calculations.rbactivesupport/lib/active_support/time_with_zone.rbの修正です。

Time#change``メソッドに:offsetオプションを指定出来るよう対応しています。合わせて、ActiveSupport::TimeWithZone#change:offset:zone`オプションを指定出来るよう対応しています。

t = Time.zone.now
# => Sat, 15 Apr 2017 05:56:34 UTC +00:00

t.change(offset: "-10:00")
# => Sat, 15 Apr 2017 05:56:34 HST -10:00

t.change(zone: "Hawaii")
# => Sat, 15 Apr 2017 05:56:34 HST -10:00

Merge pull request #28661 from bogdanvlviv/fix-dirty-attributes-if-override-attr_accessor

activemodel/lib/active_model/dirty.rbactiverecord/lib/active_record/attribute_methods/dirty.rbの修正です。

attributes readerをオーバーライドしている時(テーブルのカラム名と同じ名前のメソッドがある場合)にdirty methodが返す値に一貫性が無かった(オーバーライドされたメソッドが呼ばれる場合と呼ばれないケースがあった)のを、処理を統一するよう修正しています。

# app/models/user.rb

class User < ApplicationRecord
  def email
    super.upcase
  end
end
# before
user = User.create!(email: "test@example.com")
#<User id: 3, name: nil, email: "test@example.com", created_at: "2017-04-15 06:00:48", updated_at: "2017-04-15 06:00:48">

user.email = "dummy@example.com"
# => "dummy@example.com"

user.changes["email"]
# => ["test@example.com", "DUMMY@EXAMPLE.COM"]


# after
user = User.create!(email: "test@example.com")
#<User id: 3, name: nil, email: "test@example.com", created_at: "2017-04-15 06:00:48", updated_at: "2017-04-15 06:00:48">

user.email = "dummy@example.com"
# => "dummy@example.com"

user.changes["email"]
# => ["test@example.com", "dummy@example.com"]

Move around AR::Dirty and fix _attribute method

activemodel/lib/active_model/attribute_methods.rbactivemodel/lib/active_model/dirty.rbの修正です。

先のdirty methodについての対応で、attributeの値を取得するために_attributesというメソッドを追加していたのですが、すでに同じ用途の為の_read_attributeというメソッドがある為、そちらを使用するよう修正しています。


Fix module name [ci skip]

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

form_withメソッドのdocでFormOptionsHelperFormOptionHelperにタイポしていたのを修正しています。


Rename association_query_handler.rb to association_query_value.rb

Active Recordの修正です。

association_query_handler.rbassociation_query_value.rbに、polymorphic_array_handler.rbpolymorphic_array_value.rbにそれぞれリネームしています。

Convert association queries to PORO queriesの対応で、AssociationQueryHandlerクラス、PolymorphicArrayHandlerクラスは無くなり、上記のファイルにはAssociationQueryValueクラス、PolymorphicArrayValueクラスが残っている為、クラス名に合わせてファイル名を修正しています。


Early return in PredicateBuilder::ArrayHandler

activerecord/lib/active_record/relation/predicate_builder/array_handler.rbの修正です。

PredicateBuilder::ArrayHandler#callメソッドで、メソッドの先頭でearly returnするよう修正しています。


Merge pull request #28709 from prathamesh-sonpatki/release-notes-1

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

コンポーネントNotable Changesの項にエントリーを追加しています。


Merge pull request #28638 from bogdanvlviv/prepend_and_append_in_ruby

activesupport/lib/active_support/core_ext/array/prepend_and_append.rbの修正です。

Array#appendArray#prependメソッド定義前にメソッドがRuby本体にメソッドが定義されてないかチェックするよう修正しています。

参考:array.c: Array#append and Array#prepend