なるようになるブログ

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

rails commit log流し読み(2015/09/09)

2015/09/09分のコミットです。

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

actionpack/CHANGELOG.md

actionview/CHANGELOG.md


Merge pull request #21512 from X0nic/guides-clarify-timeout-error

rails guideのConfiguring Rails Applicationsの修正です。

ActiveRecord::ConnectionTimeoutErrorクラスについての説明から、不要なmax poolについての説明を削除しています。


Fixed Time conversion example for UTC time zone [ci skip]

activesupport/lib/active_support/core_ext/string/conversions.rbのdocの修正です。

to_timeメソッドのexampleに記載している実行結果で、実際の結果と違う箇所があったのを修正しています。


Merge pull request #21502 from bernerdschaefer/bs-polymorphic-url_for-dups-arguments

actionpack/lib/action_dispatch/routing/url_for.rbactionview/lib/action_view/routing_url_for.rbの修正です。

url_forメソッドの引数にArrayを指定した場合、引数のArrayを破壊してしまっていたのを、 引数をdupしてから処理を行い引数が変化しないよう修正しています。

下記のように、オプションを使いまわして処理を行う場合に問題があった為、対応したとの事です。

url_options = [:new, :post, param: 'value']

if current_page?(url_options)
  css_class = "active"
end

link_to "New Post", url_options, class: css_class

Use released mysql2

Gemfileの修正です。

mysql2について、リリース済みのgemを使用するよう修正しています。


Add AbstractCookieJar class.

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

全てのchained cookie jarクラスの親クラスとなるAbstractCookieJarクラスを追加しています。


Add commit method to share option normalization

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

先に追加したAbstractCookieJarクラスにoptionの設定/取得処理を行うようのメソッドを追加しています。元々PermanentCookieJarクラスで実装されていたメソッドを移動しています。


Use commit in the SignedCookieJar

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

SignedCookieJarクラスの親クラスにAbstractCookieJarを指定して、SignedCookieJarクラスから不要になったoptionの設定処理を削除しています。


Add commit in the EncryptedCookieJar

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

EncryptedCookieJarクラスの親クラスにAbstractCookieJarを指定して、EncryptedCookieJarクラスから不要になったoptionの設定処理を削除しています。


Add parse method to share deserialization logic.

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

cookie jarクラスそれぞれで行っていたdeserialize処理をメソッド(parse)に切り出しています。


Call super to remove the verify method

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

UpgradeLegacySignedCookieJar#parseメソッド内でdeserializeメソッドを直接呼び出していたのですが、同じ処理を親クラスの同じメソッド(SignedCookieJar#parse)で行っている為、 ここではdeserializeメソッドを直接呼び出さず、superで親クラスのメソッドを呼び出すよう修正しています。


Call super to remove the decrypt_and_verify method

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

UpgradeLegacyEncryptedCookieJar#parseメソッド内でdeserializeメソッドを直接呼び出していたのですが、同じ処理を親クラスの同じメソッド(EncryptedCookieJar#parse)で行っている為、 ここではdeserializeメソッドを直接呼び出さず、superで親クラスのメソッドを呼び出すよう修正しています。


Pull up parse to the legacy upgrading module

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

UpgradeLegacySignedCookieJar#parseUpgradeLegacyEncryptedCookieJar#parseメソッドが同じ内容だったので、VerifyAndUpgradeLegacySignedMessage moduleにメソッドを切り出しています。


Move the request method in to the AbstractCookieJar

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

ChainedCookieJars moduleで定義されていたrequestメソッドAbstractCookieJarクラスに移動しています。


Push key_generator into SerializedCookieJars

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

ChainedCookieJars moduleに定義されていたkey_generatorメソッドSerializedCookieJarsに移動しています。

実際使用しているのが、SerializedCookieJarsをincludeしているクラスだけの為のようです。


Fix typo in activemodel changelog

activemodel/CHANGELOG.mdの修正です。

valid? / invalid?メソッド複数のコンテキストを渡せるよう対応したコミットのCHANGELOGに記載されているexampleの実行結果が、 実際の結果と異なっていたのを修正しています。


Properly log nested parameters to Active Job

activejob/lib/active_job/logging.rbの修正です。

Active Jobのperformメソッドにネストしたパラメータを指定した場合に、ログに正しくパラメータの情報が出力されてなかたったのを、正しく出力されるよう修正しています。


use accessors instead of manipulating the hash

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

headerの値を取得/設定する際、header hashを直接操作するのではなく、ラッパーメソッド経由で処理行うよう修正しています。


avoid useless string allocations

actionpack/lib/abstract_controller/rendering.rbactionpack/lib/action_controller/metal/rendering.rbの修正です。

AbstractController::Rendering moduleの_get_content_typeメソッドで行っていたrendered_formatのStringオブジェクトへの変換処理を削除しています。

renderメソッド_set_content_typeを呼び出す際に合わせて_get_content_typeメソッドも呼び出すのですが、_set_content_typeを呼び出すのはrequest objectがあるときだけで、request objectがあるときは_get_content_typeの値は無視されてしまうので、結果、変換をしたものの使わない、という状態になってしまっていたので、そもそも変換処理を行わないようにしたとの事です。


push content_type assigment in to metal

Action Packの修正です。

content typeの取得/設定処理をmetal配下で行うよう修正しています。


ensure that content type defaults to text / html when setting charset

actionpack/test/dispatch/response_test.rbの修正です。

chartsetを設定していた場合、content typeのデフォルトがtext/htmlである事を確認するテストを追加しています。


pull content type parsing in to a method

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

Responseクラスのコンストラクタで行っていたcontent typeのパース処理を、メソッドに切り出しています。


make Content-Type header the canonical location for content-type info

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

Responseクラスのインスタンス変数として保持していたcontent typeに関する情報を、ヘッダーの適切な箇所で保持するよう修正しています。


refactor content type setting

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

content typeのパース処理をprivateメソッドに移動、及び、重複していた処理を削除しています。


remove mime type lookups when parsing the content type

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

content typeのパース処理から、mime typeのルックアップ処理を削除しています。

元々は、Mime::Typeクラスのオブジェクトで値を保持しており、オブジェクトを生成する為にルックアップ処理を行っていたのですが、オブジェクトとして値を保持してする必要がないため、ルックアップ処理を削除したようです。


handle implicit rendering correctly

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

content typeの挙動の整理をしています。

例えば、chartsetのみを設定していた場合、content headerには; charset=blahのように空の値が設定されてしまいます。このヘッダーで、再度content typeのパース処理を行った場合に、content typeに適切にnilが設定されるよう修正しています。


avoid allocations when there is no content type set

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

content typeが設定されていなかった場合、毎回ContentTypeHeader.new(nil, nil)を生成していたのを、クラス内で値を定義し、クラスロード時に一度だけインスタンス生成処理がおこなわれるよう修正しています。


remove parse_content_type parameter

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

parse_content_typeメソッドから、使用していない変数を削除しています。


mime_type will always return a string

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

content_typeメソッドから、不要なmime typeのStringへの変換処理を削除しています。


ensure that mutating headers will impact the content_type method

actionpack/test/dispatch/response_test.rbの修正です。

reponsen headerに直接Content-Typeを設定した場合に、Response#content_typeメソッドが正しい値を返す事を確認するテストを追加しています。


Fix docs of AR::Timestamp to match #15726

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

Time columns should support time zone aware attributes の対応により、time型のカラムもTimeZoneの影響を受けるようになったので、その旨Time Zoneのdocを修正しています。


Rails documentation use american english.[ci skip]

activesupport/lib/active_support/core_ext/file/atomic.rbのdocの修正です。

File.atomic_writeメソッドのdoc内にあったbehaviourbehaviorに修正しています。

behaviourは英国英語なのですが、Railsは米国英語を使うよう統一しているので、修正しています。


Added nodoc for arel method which returns object of private api. [ci skip]

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

内部APICollectionProxy#arelメソッド:nodoc:を設定しています。


Merge pull request #20921 from pboling/fix-sql-colors-in-log-subscriber

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

More granular console SQL colorationで、 sql query毎に色分け(insertは緑、selectは青とう)して出力されるようになったのですが、 queryがネストしていた場合に正しく色分け出来ていなかったのを対応、及び、rollbackやtransactionにも色をつけて表示するよう修正しています。……大分カラフルな感じに…。


Merge pull request #20080 from robertjlooby/fix_overwriting_by_dynamic_finders

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

modelで独自のfinderメソッド(find_by_xxx)を定義した場合に、そちらのメソッドが使用されるよう対応しています。

例。

class Device
  def self.find_by_mac_address(address)
    super(MacAddress.new(address).normalized)
  end
end

一度はマージされたものの、同じメソッド複数回定義されてしまうバグがあった為、直ぐrevertされています。


Revert "Merge pull request #20080 from robertjlooby/fix_overwriting_by_dynamic_finders"

という訳で先のfinderメソッドについてのコミットをrevertしています。


Remove dead code

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

使用されていないload_schema_current_if_existsメソッドを削除しています。


Invert the conditional

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

Schema#defineメソッド内のversionチェック処理を、unless + blank?を使用していたのを、if + present?を使用するよう修正しています。

-      unless info[:version].blank?
+      if info[:version].present?

Don't set the default argument

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

assume_migrated_upto_versionメソッドの第二引数のmigrations_pathsからデフォルト引数を削除しています。値は必ず渡される為との事です。


adjust method visibility according to it's usage.

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

public APIではないSchema#migrations_pathsの可視性をpublicからprivateに変更、及びnodocを設定しています。


remove dead code.

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

使用されていないmigrations_pathメソッドを削除しています。


Merge pull request #21529 from rngtng/move-migrations-paths-to-database-task

activerecord/lib/active_record/railties/databases.rakeの修正です。

db rake配下の各多数で、Migrator.migrations_pathsの代わりにActiveRecord::Tasks::DatabaseTasks.migrations_pathsに設定された値を使用するよう修正しています。

Allow global migrations_path configuration with using value from database_tasks instead of Migrator のフォローアップ対応です。


Merge pull request #21486 from bogdan/refactor-has-many-counter-cache

Active Recordの修正です。

HasManyAssociationクラスで定義していたcounter cacheに関する処理の一部を、Reflection モジュール配下に移動しています。

belons_to associationに関しては、元々Reflectionモジュールでcounter cacheの処理を定義しており、処理を統一する為に移動したようです。


Handle Content-Types that are not :json, :xml, or :url_encoded_form

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

TestRequest#assign_parametersメソッドで、Content-typeが:json, :xml, または :url_encoded_form以外の場合に、request.request_parametersに値が設定されない問題があったのを修正しています。

合わせて、不正なcontent typeを指定した場合に、RuntimeErrorをraiseするよう修正しています。


Update documentation to reflect Rack::Session::Abstract changes

actionpack/lib/action_dispatch/middleware/session/cookie_store.rbのdocの修正です。

CookieStoreクラスの親クラスがRack::Session::Abstract::IDからRack::Session::Abstract::Persistedに変わったのですが、ドキュメントが古いままだったので、親クラスの説明をRack::Session::Abstract::Persistedに修正しています。


remove dead code.

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

使用していないlast_versionメソッドを削除しています。