なるようになるブログ

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

rails commit log流し読み(2015/02/07)

2015/02/07分のコミットです。

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

activesupport/CHANGELOG.md

activejob/CHANGELOG.md

activerecord/CHANGELOG.md

railties/CHANGELOG.md


Merge pull request #14028 from uberllama/json_escape_comments

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

json_escapeメソッドのrdocに、json_escapeしたデータをそのままhtmlに挿入する場合、html_escape、または sanitizeメソッドによるエスケープ処理が必要である旨説明を追加しています。


Improve the performance of HWIDA select and reject

activesupport/lib/active_support/hash_with_indifferent_access.rbの修正です。

HashWithIndifferentAccess#selectHashWithIndifferentAccess#rejectメソッドで、tapしてselectした値を返していたのを、親クラスのwith_indifferent_accessメソッドを呼ぶすよう修正しています。

-    def select(*args, &block)
-      dup.tap { |hash| hash.select!(*args, &block) }
+    def select(*)
+      super.with_indifferent_access
     end

性能改善の為、との事だったのです、直ぐ次のコミットでrevertされています。


Revert "Improve the performance of HWIDA select and reject"

という訳で、先のHashWithIndifferentAccessの性能改善のコミットをrevertしています。


Indicate link_to creates an anchor element

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

link_toメソッドの説明で、"linkタグを生成する"と記載があったのですが、この説明だと、"タグ"の方を示してしまっていると思われるので、"Anchor 要素を作成する"に説明を修正しています。


Merge branch 'rm-ntp'

activesupport/lib/active_support/number_helper/number_to_rounded_converter.rbの修正です。

number_to_percentageメソッドprecisionオプションにnilを指定した場合に、元々の精度のまま値を返すよう修正しています。

number_to_percentage(1000.1, precision: nil)
# => "1000.1%"

Allow a symbol to be passed to attribute, in place of a type object

ActiveRecordの修正です。

attributeメソッドの引数に、 type objectの代わりにSymbolを渡せるよう修正しています

class StoreListing < ActiveRecord::Base
  attribute :price_in_cents, :integer
end

Use keyword argument in the find_in_batches API

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

Batches#find_eachfind_in_batchesメソッドの引数をキーワード引数に修正しています。


Significantly improve the performance of _read_attribute on JRuby

activerecord/lib/active_record/attribute_methods/read.rbactiverecord/lib/active_record/attribute_set.rbの修正です。

JRuby とそれ以外とでブロックの受け渡しの処理を変えています。

-      def _read_attribute(attr_name) # :nodoc:
-        @attributes.fetch_value(attr_name.to_s) { |n| yield n if block_given? }
+      if defined?(JRUBY_VERSION)
+        # This form is significantly faster on JRuby, and this is one of our biggest hotspots.
+        # https://github.com/jruby/jruby/pull/2562
+        def _read_attribute(attr_name, &block) # :nodoc
+          @attributes.fetch_value(attr_name.to_s, &block)
+        end
+      else
+        def _read_attribute(attr_name) # :nodoc:
+          @attributes.fetch_value(attr_name.to_s) { |n| yield n if block_given? }
+        end
       end

呼び出し先のfetch_valueでもblock_given?のチェックが行われており、これが性能に影響を出してしまっているとの事。

JRubyでは、上記のようなケースの場合に、block_given?のチェックを省略出来るよう対応されているとのこと。JRubyの方のPRはこちら。因みにJRubyの方にPR出したのは、このコミットをrailsコミッターである@sgrif本人。凄いなあ。


Add an :only option to perform_enqueued_jobs to filter jobs based on

activejob/lib/active_job/queue_adapters/test_adapter.rbactivejob/lib/active_job/test_helper.rbの修正です。

assert_performed_jobsメソッドの引数に、job classを指定出来る:onlyオプションを追加しています。

    def test_hello_job
      assert_performed_jobs 1, only: HelloJob do
        HelloJob.perform_later('jeremy')
        LoggingJob.perform_later
      end
    end

特定のクラスのJobが実行されている事を確認するようですね。


Stoping using Relation#merge in default_scoped

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

default_scopedメソッドで、最初にbuild_default_scopeでscopeの生成を行い、scopeがあった場合のみscopeのmergeを行うよう修正しています。


Raise ArgumentError when passing nil to Relation#merge

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

Relation#mergeメソッドの引数にnilfalseが渡された場合に、ArgumentErrorをraiseするよう修正しています。


Docs pass for the attributes API

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

Attributes moduleの各メソッドにdocを追加しています。


Remove documentation tasks

ドキュメント生成用のタスク(doc:app, doc:rails, and doc:guides)を削除しています。

経験上、doc:appでdocを生成する事は無いだろうとの事で、 doc:railsdoc:guidesについては、オンラインでdoc見るから要らないだろう、との事で削除されたようです。


README.rdoc -> README.md for newly generated applications

railties/lib/rails/generators/rails/app/app_generator.rbの修正です。

新規にappをgenerateした際に生成されるreadmeのフォーマットが、rdocからmarkdownに変更になっています。

doc:appタスクのサポートの為にrdocを生成していたらしく、doc:appが削除された事に合わせて、markdownに変更したとの事です。


Remove reference to the now done documentation.rake

railties/lib/rails/tasks.rbの修正です。

タスクの一覧から、documentation.rakeを削除しています。


Grammar and RDoc formatting

activerecord/lib/active_record/attributes.rbactiverecord/lib/active_record/type/value.rbのdocの修正です。

グラマー及びフォーマットの修正を行っています。


A symbol can be passed to attribute, which should be documented

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

attributesにSymbolが渡せる旨説明を追加しています。


Document the usage of the default option to attribute

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

attributeのデフォルトオプションの設定方法についての説明を追加しています。


Fixed undefined method `i18n_key' for nil:NilClass for labels in non AR form_for

actionview/lib/action_view/helpers/tags/translator.rbの修正です。

form_forメソッドの引数にActiveRecord以外のオブジェクトを渡した場合に、undefined method でエラーになってしまうバグがあったのを修正しています。


Add link to the show action in the getting started

rails guideのGetting Started with Railsの修正です。

サンプルアプリのindex.html.erbにshow actionへのリンクが無かったので、リンクを追加しています


use kwargs instead of xhr method. refs #18771.

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

deprecateになったxhrメソッドを使用しているテストがあったのを、get xhr:trueのフォーマットに修正しています。


make zones_map private

activesupport/lib/active_support/values/time_zone.rbの修正です。

ActiveSupport::TimeZones.zones_mapメソッドの可視性をprivateに変更しています。


remove noise from AM tests

actionmailer/test/test_helper_test.rbの修正です。

deliver_laterメソッド呼び出し時に不要なメッセージが出力されてしまっていたので、 silence_streamでstdoutの出力を抑止するよう修正しています


NameError#missing_name? can jsut use NameError#name if the arg is a Symbol

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

missing_name?メソッドで引数がSymbolだった場合に、NameError#missing_nameメソッドを呼び出して、エラーメッセージから値を値を取得していたのですが、 NameError#nameで必要な値がとれるので、NameError#nameを使用するよう修正しています。


Merge pull request #18835 from jtmkrueger/master

guides/assets/images/favicon.icoの修正です。

rails guideのfaviconRubyのiconからRailsのiconに修正しています。