なるようになるブログ

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

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

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

DBにMySQLを使用し、configファイルにvariablesを指定した際に正しく設定されていなかったバグの修正が含まれています。


split nil / Hash cases in url_for

ActionView::RoutingUrlFor#url_forメソッドの修正です。optionsがnil/Hashだった場合に同じ処理だったのですが、処理を分岐しています。

Hashの場合optionsの中身のチェック等の処理が必要ですが、nilの場合はチェック処理不要なので、分岐したようです。


Stringify variables names for mysql connections

DBにMySQLを使用し、configファイルにvariablesを指定した際に正しく設定されていなかったバグを修正しています。

production:
  adapter: mysql2
  username: xxx
  password: xxx
  database: aod
  pool: 5
  timeout: 5000
  encoding: utf8
  variables:
    sql_mode: 'ansi'

上記設定を記載したファイルをロードした際に、

:variables=>{"sql_mode"=>"ansi", :sql_auto_is_null=>0, :wait_timeout=>2147483, :sql_mode=>"STRICT_ALL_TABLES"}

このようにsql_modeが2回設定されてしまい、configファイルに設定したsql_modeが反映されないバグがありました。

configファイルに記載された値のkeyがStringで、内部で設定している値のkeyがSymbolだったのが問題なので、内部で設定している値のkeyもStringで設定するよう修正しています。


don't allocate string on hash access

ActionView::RoutingUrlFor#url_forメソッドの修正です。 envにアクセスする際に、Stringをfreezeしています。

-      if (same_origin = _routes.equal?(env["action_dispatch.routes"])) ||
+      if (same_origin = _routes.equal?(env["action_dispatch.routes".freeze])) ||

freezeしておくとStringが再利用されて、メモリの効率がちょっと良いからですね。


do not allocate strings while creating urls

ActionController::UrlFor#url_optionsメソッドの修正です。修正内容は上記コミットと同じで、Stringにfreezeを指定しています。


eliminate conditional when sending the named route method

ActionDispatch::Routing::PolymorphicRoutes#polymorphic_urlの修正です。

一つ変数を追加して、不要な判定処理を削除しています。


avoid calling extract_record multiple times

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

ActionDispatch::Routing::PolymorphicRoutes#routing_typeの引数にrecordを追加して、extract_recordの呼び出しを減らすようにしています。


[skip ci] Document: required via option in match routing method.

ActionDispatch::Mapping::Base#rootメソッドのdocの修正です。

routingにmatchを使用する際、viaオプションが必要になったのですが、 docにその説明が無かったので、修正してい追記しています。


Add documentation to select_tag for :selected option

actionview/lib/action_view/helpers/form_tag_helper.rbのdocの修正です。

select_tag:selectedオプションについての説明が無かったので、追記してます。


Give real privacy to class methods in AR::PredicateBuilder activerecord/lib/active_record/relation/predicate_builder.rbの修正です。

クラスメソッドをprivate化するのに、privateメソッドを使用してしまっているのを、private_class_methodメソッドに修正しています。

前回違う箇所でも同じ修正があったので、他にもありそうですねえ。