なるようになるブログ

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

rails commit log流し読み(2016/04/20)

2016/04/20分のコミットです。

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

actionview/CHANGELOG.md

activesupport/CHANGELOG.md


Update send_data documentation [ci skip]

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

#send_dataメソッドのdoc内の行の終端に.が無い箇所があったので、追加しています。


Remove reference to unknown method dirty? to docs

rails guideのUsing Rails for API-only Applicationsの修正です。

存在しないメソッド(dirty?)について説明が行われている箇所があったのを削除しています。


Merge pull request #24567 from Edouard-chin/ec-method-typo

actionmailer/lib/action_mailer/test_case.rbの修正です。

テスト用のメソッド名でタイポ(clear_test_deliviers -> clear_test_deliveries)していた箇所があったのを修正しています。


Define arel_visitor method on all adapters

Active Recordの修正です。

arel visitorの生成処理にArel::Visitors::VISITORSを使用しabstract adapterで行うよう昨日修正が行われたのですが、Arel::Visitors::VISITORS定数がarel側で削除済みだった(Delete not used codes)為、各connection adapterで、それぞれのadapter毎のvisitorsクラスを指定し処理を行うように修正しています。


- Added documentation for ActiveJob queue adapter for a specific job.

rails guideのActive Job Basicsの修正です。

Setting the Backendの項に、job class毎にqueue adapterを指定する場合についての説明を追加しています。


Database comments: Treat blank comments as no comment. Don't dump blank comments.

Active Recordの修正です。

commentが空の場合に、dump fileにcommentを生成しないよう修正しています。


Remove unecessary comment

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

テストの終端にあった不要なコメントを削除しています。

-end # if ActiveRecord::Base.connection.supports_comments?
+end

実際は不要なコマンドではなく、ifの終端をわかりやすくする為のコメントだったようなのですが、そのまま削除されています。


mention rails 5 instead of rails 4 in bin/rails for plugins

railties/lib/rails/generators/rails/plugin/templates/bin/rails.ttの修正です。

rails pluginで生成されるrailsスクリプト内のコメントに、…run "rails" with Rails 4 gems…というようにRailsのバージョンを指定したコメントがあったのを、バージョンの指定を削除しています。


Merge pull request #24031 from samphilipd/sam/do_not_clobber_options_in_route_definitions

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

#scopeメソッドで、引数のoptions自体の値を変更するようになってしまっていたのを、変更しないよう修正しています。

-            (options[:defaults] ||= {}).reverse_merge!(defaults)
+            options[:defaults] = defaults.merge(options[:defaults] || {})
HTML = { constraints: { format: :html } }.freeze
scope HTML do
  get 'x'
end

上記のように、freezeした値を渡したり、optionsの使いまわしをしたい時に問題になってしまう為。


Fix test_blank_columns_created_in_block

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

先ほど、commentが空の場合に、dump fileにcommentを生成しないよう修正されたのですが、columnについてのcommentで修正が漏れてしまっていた箇所があったので、追加で修正しています。


Ensure Cache#inspect doesn't block concurrent cache writes

actionview/lib/action_view/template/resolver.rbの修正です。

ActionView::Resolver::Cache#inspectメソッドを追加しています。

+      def inspect
+        "#<#{self.class.name}:0x#{(object_id << 1).to_s(16)} keys=#{@data.size} queries=#{@query_cache.size}>"
+      end

Object#inspectだと全てのインスタンス変数を再帰的に検査するので、表示されるべきではない内部の状態についてのデータも表示されてしまう、かつ、並列で同時に実行した場合に他のスレッドのcacheの書き込みをブロックしてしまう事があるので、必要な情報だけを表示するようメソッドを追加したようです。


Merge pull request #23869 from oreoshake/to-sentence-html-safety

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

ActionView::Helpers::OutputSafetyHelper moduleに、to_sentenceメソッドを追加しています。

Array#to_sentenceメソッドの、html safe版との事です。

helper.to_sentence(%w(< > & ' "))
# => "&lt;, &gt;, &amp;, &#39;, and &quot;"

helper.to_sentence(%w(<script>))
# => "&lt;script&gt;

helper.to_sentence(['one', 'two', 'three'], words_connector: ' & '.html_safe)
# => "one & two, and three"

Add CHANGELOG entry for #23869

actionview/CHANGELOG.mdの修正です。

先のto_sentenceメソッドの対応について、CHANGELOGにentryを追加しています。


Merge pull request #24225 from neumayr/date_select_helper_with_css_classes_accept_hash

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

date_selectメソッド:with_css_classesオプションで、項目(yearmonthday等)毎に個別のclassを指定出来るよう修正しています。

CHANGELOGより。

<%= f.date_select :birthday, with_css_classes: { month: "my-month", year: "my-year" } %>
<select id="user_birthday_3i" name="user[birthday(3i)]"></select>
<select id="user_birthday_2i" name="user[birthday(2i)]" class="my-month"></select>
<select id="user_birthday_1i" name="user[birthday(1i)]" class="my-year"></select>

Merge pull request #20625 from Envek/add_country_zones_method

Active Supportの修正です。

任意の国のtimezoneの一覧を取得する為の、ActiveSupport::TimeZone.country_zonesメソッドを追加しています。

ActiveSupport::TimeZone.country_zones('us').map(&:to_s)
# => ["(GMT-10:00) Hawaii", "(GMT-09:00) Alaska", "(GMT-08:00) Pacific Time (US & Canada)", "(GMT-07:00) Arizona", "(GMT-07:00) Mountain Time (US & Canada)", "(GMT-06:00) Central Time (US & Canada)", "(GMT-05:00) Eastern Time (US & Canada)", "(GMT-05:00) Indiana (East)"]

ActiveSupport::TimeZone.country_zones('fr').map(&:to_s)
# => ["(GMT+01:00) Paris"]

また、同じ結果を表示する為のtask(time:zones)も追加されています。

./bin/rails "time:zones[US]"

* UTC -10:00 *
Hawaii

* UTC -09:00 *
Alaska

* UTC -08:00 *
Pacific Time (US & Canada)

* UTC -07:00 *
Arizona
Mountain Time (US & Canada)

* UTC -06:00 *
Central Time (US & Canada)

* UTC -05:00 *
Eastern Time (US & Canada)
Indiana (East)

undef_method is not needed

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

#select_rows#executeundef_methodで見えないようにしていたのを止めて、代わりにNotImplementedErrorをraiseするように修正しています。

      def select_rows(sql, name = nil, binds = [])
+        raise NotImplementedError
       end
-      undef_method :select_rows

subclassで実装されている事が期待されているメソッドであり、NotImplementedErrorをraiseするのが正しい挙動の為。 因みに、undef_methodしていたのは、subclassで該当のメソッドが実装されていない場合に、RDocが生成されないようする為、だったようです。


[ci skip] Small grammar fix

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

date_selectメソッド内のdocのグラマーの修正を行っています。


Fix example for css_class_attribute and fix indentation

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

css_class_attributeメソッドのコードのインデントの修正、及びdoc内のexampleコードで、オプションの指定の仕方が間違っていたのを修正しています。


use rails command in time:zones task desc [ci skip]

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

先ほど追加されたtime:zones taskのdescription内のexampleで、rakeコマンドを使うようになっていたのを、railsコマンドを使用するよう修正しています。


~3.5x speedup of String#blank? for empty strings

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

String#blank?メソッドで、Stringが空かどうかのチェックに正規表現(BLANK_RE = /\A[[:space:]]*\z/)を使用してチェックしているのですが、正規表現でチェックするより前に、#empty?メソッドでチェックを行うよう修正しています。

  def blank?
-    BLANK_RE === self
+    # In practice, the majority of blank strings are empty. As of this writing
+    # checking for empty? is about 3.5x faster than matching against the regexp
+    # in MRI, so we call the predicate first, and then fallback.
+    #
+    # The penalty for blank strings with whitespace or present ones is marginal.
+    empty? || BLANK_RE === self
   end

本当に只の空文字(スペース等も無い空文字)の場合に、こちらの方が早い為。