なるようになるブログ

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

rails commit log流し読み(2014/05/10)

2014/05/10分のコミットです。

インスタンスに依存しているassociationをjoin, preload, eager loadするのはdeprecateになりました。


Use ruby 2.1.2 on travis

.travis.ymlの修正です。travisで2.1.2を使うように修正しています。早い。


[ci skip] doc Http::Headers methods

ActionDispatch::Http::Headersにdocを追加しています。


[ci skip] doc ActiveSupport::TimeWithZone#to_s

ActiveSupport::TimeWithZone#to_sメソッドのdocを修正しています。

to_sメソッドって引数にフォーマット指定出来たんですね。知らなかった。


Reverts "Fix bugs with changed attributes tracking when transaction gets rollback"

一昨日にあったActiveRecord::Transactionsの修正をrevertしてます。

rollbackした時に、dirtyな値は保存スべきではない、との事です。

個人的にも、変わらないのが良い気がします。このコミットについてのPRはこちら。


just call the method and assert the return value

actionpack/test/controller/routing_test.rbの修正です。

内部メソッドを使ってテストをしていた処理を、assert_equalに修正しています。


Only need MINOR version level to test Ruby 2.1.x on Travis

.travis.ymlの修正です。

バージョンの指定にTEENYまで指定していたのですが、travisではMINORまで指定すれば良いらしいので、TEENYを削除しています。


test, regression test for has_many with instance dependent scope.

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

インスタンス経由のスコープのテストの追加、であってるかなあ。


Documentation, add examples of using an Enum scope

ActiveRecord::Enumのdocの修正です。

生成されるscopeのexampleを追加しています。


use unless and || since these options are boolean

ActionDispatch::Http::URL#build_host_urlメソッドの修正です。

booleanの値が設定されているかのチェック処理で、if.. &&を使用していのを、unless .. ||に修正しています。

- if options[:host].blank? && options[:only_path].blank?
+ unless options[:host] || options[:only_path]

blank?が削除されて、スッキリしましたね。


use fnmatch to test for case insensitive file systems

ActionView::Resolver::PathResolver#queryメソッドの修正です。

ファイル名のチェックにFile.fnmatchを使うように修正しています。

File.fnmatchについてはこちらを参照。ファイル名のパターンマッチ用のメソッドですね。


[ci skip] add example to AR#assign_attributes

ActiveRecord::AttributeAssignment#assign_attributesメソッドのdocの修正です。

exampleを追加しています。


don't mutate the options hash, so we don't have to dup

ActionDispatch::Http::URL#url_forメソッドの修正です。

pathを作成する際、引数のoptionsのコピーを生成し、その値を操作して作成していたのを、コピーを作成しないように修正しています。

コミットログにavoids extra hash allocations on each callともあるので、繰り返し呼ばれる処理でhashの生成処理を避ける為かと。


skip dealing with params if none are provided

こちらもActionDispatch::Http::URL#url_forメソッドの修正です。

options[:params]が設定されてないとき、paramsの操作処理をしないようにしています。

また、以下の4点を避けるよう修正しているとの事です。

  1. A slow call to Hash#slice
  2. An is_a? test
  3. Extra hash allocations (from slice)
  4. String allocations

Hash#slice遅いんですね。なるほど。


Fix broken proc syntax for 1.9.3

activerecord/test/models/author.rbの修正です。

1.9.3でproc処理が動かなくなっていたのを修正しています。

-  has_many :posts_with_signature, -> (record) { where("posts.title LIKE ?", "%by #{record.name.downcase}%") }, class_name: "Post"
+  has_many :posts_with_signature, ->(record) { where("posts.title LIKE ?", "%by #{record.name.downcase}%") }, class_name: "Post"

解りづらいのですが、->の後ろにスペースがある/なしの違いです。 これ、とても気付きづらいんですよね…。


deprecate, join, preload, eager load of instance dependent associations.

インスタンスに依存しているassociationを記載している場合のjoin, preload, eager load処理はdeprecateになる旨WARNINGを出すよう対応しています。 インスタンスに依存しているassociationをjoin, preload, eager loadした際に、WARNINGを出すよう対応しています。

issueからサンプルを。

class User < ActiveRecord::Base
  has_many :posts, ->(record) { where(title: record.name)}
end

class Post < ActiveRecord::Base
  belongs_to :user
end
$ rails c
irb(main):006:0> User.where(:name => 'zzz').includes(:posts)
  User Load (5.8ms)  SELECT `users`.* FROM `users` WHERE `users`.`name` = 'zzz'
(Object doesn't support #inspect)

:postsインスタンスを引数にしてwhereを行っているのですが、このようなscopeに対してincldes行うと下記のようなwarningが出力されるようになります。

DEPRECATION WARNING: The association scope 'posts' is instance dependent (the scope block takes an argument).
Preloading happens before the individual instances are created. This means that there is no instance
being passed to the association scope. This will most likely result in broken or incorrect behavior.
Joining, Preloading and eager loading of these associations is deprecated and will be removed in the future.

そもそも、現状動いていない or 誤った振る舞いをしている為、deprecateにした、との事です。

ちゃんと考えると動かないだろうと思うのですが、ぱっと見ちゃんと動きそうに見えるんですよねえ。


copy edits [ci skip]

ActionDispatch::Http::Headersのdocの修正です。

改行、スペースの追加等細かい修正です。


minor change in AR readme [ci skip]

activerecord/README.rdocの修正です。

put on railsin Railsに修正。