なるようになるブログ

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

rails commit log流し読み(2014/06/03)

2014/06/03分のコミットです。

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

activesupport/CHANGELOG.md

activerecord/CHANGELOG.md


Merge pull request #15379 from xuanxu/rational_precision

ActiveSupport::NumberHelper::NumberConverter::NumberToRoundedConverter#convertメソッドの修正です。

ActiveSupport::NumberHelper.number_to_roundedメソッドの引数にRationalクラスを指定した場合に、結果がおかしくなっていたのを修正しています。

# before
  ActiveSupport::NumberHelper.number_to_rounded Rational(1000, 3), precision: 2  #=> "330.00" 

# after
  ActiveSupport::NumberHelper.number_to_rounded Rational(1000, 3), precision: 2  #=> "333.33"

just use assert

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

assert_equalを使用していた箇所をassertに修正しています。

-    assert_equal true, child.save
+    assert child.save, 'child object should be saved' 

trueかどうか確認するには、assertの方が明確ですね。


File.exist? instead of File.exists? in bin/setup

railties/lib/rails/generators/rails/app/templates/bin/setupの修正です。

File.exists?メソッドの代わりにFile.exist?メソッドを使用するよう修正しています。File.exists?でdeprecateになってたんですね。知らなかった。


Add missing colon to internal

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

:internalにコロンが足りてなかったのを追加しています。


Remove unused initialize_attributes method

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

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


Fix typo in ActionController Overview

rails guideのAction Controller Overviewの修正です。

"sensible"ではなく、"sensitive"を使うべき、との事で修正しています。

意味が良く解らなくてググったらこんな記事が間違いやすい英語:Sensibleとsensitive。難しいなあ。


concat is a hotspot (via AV#append=), so just directly define the methods

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

define_methodメソッドを使ってメソッドを定義していたのをdefを使うように修正しています。

-    %w[concat prepend].each do |method_name|
-      define_method method_name do |value|
-        super(html_escape_interpolated_argument(value))
-      end
+    def concat(value)
+      super(html_escape_interpolated_argument(value))
+    def prepend(value)
+      super(html_escape_interpolated_argument(value))
+    end

ActionView#append=がhotspotだから、とコミットログには記載されていますが、よく解らず。

alias :concat  :<<
alias :append= :<< 

こっちはこっちでalias設定してるんだよなあ。


reduce AS::SafeBuffer allocations

ActiveSupport::String::SafeBuffer#html_escape_interpolated_argumentメソッドの修正です。

元々はActiveSupport::SafeBufferクラスを返していたのですが、ActiveSupport:SafeBufferクラスである必要性は無いとの事で、ERB::Util.hを使用しないよう修正しています。


drastically reduce object allocations

ERB::Util.unwrapped_html_escapeメソッドを新設しています。

元々HTML escape処理では、escape処理したStringをActiveSupport::SafeBufferでラップしていました。

class String
  def html_safe
    ActiveSupport::SafeBuffer.new(self)
  end
end

こんな感じですね。なので、HTML escape処理する度に、ActiveSupport::SafeBufferインスタンスが生成されていたのですが、新設されたunwrapped_html_escapeでは、escape処理した後、ActiveSupport::SafeBufferでラップしないようにしています。

で、幾つかのメソッドunwrapped_html_escape処理を使うようにした結果aaronのテストアプリケーションでは、ActiveSupport::SafeBufferのオブジェクト数が1527 / req から500 / reqから減ったとの事です。すごい。


call capture fewer times from form_for

ActionView:: Helpers::FormTagHelper#form_tag_in_blockメソッドform_tag_with_bodyメソッドにリネームして、引数をblockからcontentに修正しています。

元々form_tag_in_blockの中で、captureメソッドでbodyの情報を取得していたのを、呼び出し側で対応するよう修正しています。captureのcall回数が減らす為ですかね。


fix polymorphic? method and reuse it

ActiveRecord::Reflection::polymorphic?メソッドの修正です。

options.key? :polymorphicoptions[:polymorphic]に修正しています。各箇所のpolymorphicのチェック処理をpolymorphic?メソッドを使用するように修正しています。


pg test, examples for default values and schema dumping of point types.

activerecord/test/cases/adapters/postgresql/geometric_test.rbの修正です。

default value、schema dumpingに関するテストを追加しています。


pg, preserve point type when schema dumping.

PostgreSQLのConnectionAdapterの修正です。

typeにpointを追加しています。

@connection.create_table('postgresql_points') do |t|
  t.point :x
  t.point :y, default: [12.2, 13.3]
  t.point :z, default: "(14.4,15.5)"
end

migratationファイルにも指定可能です。


test pg, we don't care about the internal state of column#default.

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

column#defaultに関するテストを削除しています。

column#defaultは内部の状態なので、テストする必要は無いとの判断らしいです。


test pg, move bit string type tests into bit_string_test.rb.

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

activerecord/test/cases/adapters/postgresql/bit_string_test.rbを新規に作成してbit string typeのテストをそちらに移動しています。


Refactor determination of whether the field has changed

ConnectionAdaptersの修正です。

file変更時の取り扱いについてリファクタリングしています。


pg, preserve type when schema dumping bit and bit varying columns.

PostgreSQLのConnectionAdapterの修正です。

typeにbitbit_varyingを追加しています。

@connection.create_table('postgresql_bit_strings') do |t|
  t.bit :a_bit, default: "00000011", limit: 8
  t.bit_varying :a_bit_varying, default: "0011"
end

こんな感じで。


Respect limit for PG bit strings

PostgreSQLのConnectionAdapterの修正です。

上記コミットで追加されたbitに関するのソースの微修正です。String -> Symbolに変更等を行っています。


Refactor quoting of binary data to not be based on the column type

ConnectionAdaptersの修正です。

binary dataのquote処理についてリファクタリングしています。

_quoteメソッドを新設し、そちらに処理をまとめています。