なるようになるブログ

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

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

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

CHANGELOGにのったコミットは以下の通りです(詳細は本文参照)。

activesupport/CHANGELOG.md

activerecord/CHANGELOG.md


Fix confusing exception in ActiveSupport delegation

Module::NoMethodError::DelegationError#delegateメソッドの修正です。

delegate先のメソッドでエラーが起きた際に、エラーの内容がおかしい事があったのを修正しています。

class A
  delegate :even?, to: :whatever

  def whatever
    "arbitrary_object".even?
    123
  end
end

# before
  # Module::DelegationError: A#even? delegated to whatever.even?, but whatever is nil: #<A:0x007fc6aea2d768>

# after
  # NoMethodError: undefined method `even?' for "arbitrary_object":String

Delegate type_cast to injected type object in mysql

MySQLのDBAdapterの修正です。

type objectにTimeValueを追加し、time型の場合そちらを使用するようにしています。


Have Postgres OID types inherit from general types

PostgresのDBAdapterの修正です。

OID型についても、通常のtype valueオブジェクトを使用するように修正しています。


Use general types for mysql fields

MySQLのDBAdapterの修正です。

fieldについても、通常のtype objectを使うよう修正しています。


Replace type_cast case statement with delegation

DBAdapterの修正です。

各adaperで行っていたtype_cast処理をtype objectのに移譲しています。


fix multiple hash preloads. Fixes #14994

ActiveRecord::Associations::Preloader#preloaders_for_hashメソッドの修正です。

複数のHashを引数にしてpreloadメソッドを呼び出した際に、loadされないバグがあったのを修正しています。


make the each visitor top-down left-right

ActionDispatch::Journey::Visitors::Visitor#visitメソッドの修正です。

superメソッドの呼び出し順序を変更しているのは解るのですが、どのような意図の修正かが解らない…。


prepopulate the dispatch cache so we don't need the ThreadSafe cache.

actionpack/lib/action_dispatch/journey/visitors.rbの修正です。

ThreadSafe::Cacheを削除しています。


Use the generic type map object for mysql field lookups

MySQLのDBAdapterの修正です。

type判定用にHashLookupTypeMapクラスを新規に作成し、そちらのクラスを使用するよう修正しています。


translate AST to a formatter before url generation

actionpack/lib/action_dispatch/journey/route.rbの修正です。

url生成前に、ASTの解析処理を実施するよう修正しています。


cache the formatter on the path object

ActionDispatch::Journey::Path::Patternクラスの修正です。

Patternクラスにpath objectのformat情報を保持するよう修正しています。


remove dead code

actionpack/lib/action_dispatch/journey/visitors.rbの修正です。

使用しなくなったコードを削除しています。


Delegate predicate methods to injected type object on Column

DBAdapterの修正です。

text?, number?, binary?メソッドをcast_typedelegateするよう修正しています。

リファクタリング


Use the generic type map for PostgreSQL OID registrations

PostgreSQLのDBAdapterの修正です。

OIDについてもHashLookupTypeMapを使用するよう修正しています。


Inline typecasting helpers from Column to the appropriate types

DBAdapterの修正です。

activerecord/lib/active_record/connection_adapters/column.rbで行っていた型キャストの処理を、各type objectに移動しています。


Merge pull request #11346 from tomykaira/fix_10257

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

Basic認証のチェック処理で、'Basic'以外のスキームでも認証処理が通ってしまっていたバグを修正しています。


Delegate type_cast_for_write to injected type object

DBAdapterの修正です。

type_cast_for_writecast_typedelegateするよう修正しています。


fix variable names, only pass hashes to the positional args method

actionpack/lib/action_dispatch/routing/route_set.rbの修正です。

変数名の修正。


fewer hash allocations when calling url_for

ActionDispatch::Routing::UrlFor#url_forメソッドの修正です。

Hashの生成処理を少し減らしていいます。


fewer method calls and string garbage when there is no user/password

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

オプションにuser/passwordが設定されてない場合に、不要なString生成処理を減らしています。


push arg checking up

ActionDispatch::Routing::UrlFor#url_forメソッドの修正です。

引数のチェック処理をメソッドの最初で行うよう修正しています。


push only_path conditional up

actionpack/lib/action_dispatch/http/url.rbの修正です。

こちらも引数のチェック処理の順序の修正しています。


mutate the path string to avoid object allocations

ActionDispatch::Routing::UrlFor#url_forメソッドの修正です。

subではなく、sub!を使うようにして、不要な変数生成処理を削除しています。


fewer string allocations per url_for

ActionDispatch::Routing::UrlFor#url_forメソッドの修正です。

処理の順番修正し、String生成処理を減らしています。


we don't use this parameter for anything, so rm

ActionDispatch::Journey::Formattr##generateメソッドの修正です。

使用していない変数の削除。


Merge pull request #15154 from msgehard/move_password_field

activemodel/lib/active_model/secure_password.rbの修正です。

attr_reader :passwordを宣言している箇所を修正しています。


Prevented belongs_to: touch propagating up if there are no changes being saved

belongs_to: touchを使用している際、値が更新された場合のみ、touch処理が行われるよう修正しています。


Delegate klass to the injected type object

DBAdapterの修正です。

klasscast_typedelegateするよう修正しています。


Revert "Revert "Merge pull request #8313 from alan/only_save_changed_has_one_objects""

こちらのPRのrevertをrevertしています。ややこしい。

has_one associationsを使用している時に、子のオブジェクトの値が変わったときのみ、save処理を行うよう修正しています。

issueはこちら。ちょっとややこしいので、後でもうちゃんと読もう。


Merge pull request #14544 from jefflai2/named_scope_sti

scoped blocksをinstance_evalで実行するよう修正しています。

ActiveRecord::Baseを継承したclassを更に継承したクラスでscope blocksを使用していた場合に、生成させるクエリーがおかしくなる場合があったようです。

issueから

class User < ActiveRecord::Base
  belongs_to :role
end

class Term < ActiveRecord::Base
end

class Role < Term
end

class ProductCategory < Term

   belongs_to :realm, class_name: 'Role'

   scope :view_as_realm, -> {
        where realm: user.role

    }
end
SELECT `terms`.* FROM `terms` WHERE `terms`.`type` IN ('ProductCategory') AND `terms`.`type` IN ('Role') AND `terms`.`id` = 193 ORDER BY `terms`.`id` ASC LIMIT 1

何故かクエリーにクラス名が。

なお、4.0.0 - 4.0.2の間で壊れてしまったようです。


Merge pull request #10887 from sakuro/deep_transform_keys_in_nested_arrays

Hash#deep_transform_keysHash#deep_transform_keys!がネストしたArrayも引数にとれるように修正しています。

使えそうなケースがありそうですが、忘れそう…。


Remove redundant code.

actionpack/lib/action_dispatch/middleware/public_exceptions.rbの修正です。

不要な判定処理を削除しています。


Fix polymorphic eager load with foreign_key as String.

polymorphicを使用している、かつ、外部keyにStringを使用している場合に、eager loadingをするとエラーになるバグを修正しています。

これ割と問題になるケースが多そうな。polymorphicがあまり使われてないからですかねえ。


pg, extract money tests into separate file.

PostgreSQLのDBAdapterのテストの修正です。

activerecord/test/cases/adapters/postgresql/money_test.rbを新規に作成して、money関連のテストはそこに集約しています。


push extract_scale to the Type.

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

extract_scaledelegate先をcast_typeメソッドに修正しています。


build fix, use lambda syntax that ruby 1.9.3 understands.

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

lambdaを使用している箇所で、スペースを削除。

-  scope :special_parent, -> (special_rating) { where parent_id: special_rating.special_comment.id }
+  scope :special_parent, ->(special_rating) { where parent_id: special_rating.special_comment.id }

fix formatting and text for ActionController::Redirecting doc

ActionController::Redirectingのdocの修正です。

引数の説明が誤っていたのを修正しています。