なるようになるブログ

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

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

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

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

actionview/CHANGELOG.md

activerecord/CHANGELOG.md

activesupport/CHANGELOG.md


Relpace =~ Regexp.new str with .include? str in AC::Base#_valid_action_name?

actionpack/lib/abstract_controller/base.rbの修正です。

_valid_action_name?メソッドRegexpでチェックしていた処理をString#include?を使うよう修正してます。

-        action_name !~ Regexp.new(File::SEPARATOR)
+        !action_name.to_s.include? File::SEPARATOR

書き方としてより自然だというのと、String#include?の方が早いから、との事です。

コミットログにbenchmark結果がついていたので、参考までに。

require 'benchmark/ips'

Benchmark.ips do |x|
  x.report('include?') { !"index".to_s.include? File::SEPARATOR }
  x.report('   !~   ') { "index" !~ Regexp.new(File::SEPARATOR) }
end

__END__
Calculating -------------------------------------
            include?     75754 i/100ms
               !~        21089 i/100ms
-------------------------------------------------
            include?  3172882.3 (±4.5%) i/s -   15832586 in   5.000659s
               !~      322918.8 (±8.6%) i/s -    1602764 in   4.999509s

Further simplify changed? conditional for numeric types

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

changed?メソッドnil及び0のケースを特別扱いしていたのですが、nilについては、 changed?では考慮する必要が無いとの事で、0のケースのみハンドリングするよう修正しています。


Add logger.debug? guard to ActionMailer::LogSubscriber#process

ActionMailer::LogSubscriber#processメソッドの修正です

logger.debug?がfalseの時にearly returnするよう修正しています。

こちらも性能改善の一貫。


[ci skip] Fix typo in 4.1 upgrade/flash structure

rails guideのA Guide for Upgrading Ruby on Railsの修正です。

typoの修正です。


excerpt() now accepts regular expression instances as phrases.

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

excerptメソッドの第二引数にRegexpインスタンスを渡せるよう対応しています。


highlight() now accepts regular expressions as well.

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

こちらはhighlightメソッドの第二引数にRegexpインスタンスを渡せるよう対応しています。


Fix has_and_belongs_to_many in a namespaced model pointing to a non namespaced model

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

継承したクラスでhas_and_belongs_to_manyを使用するとエラーになっていたのを修正しています。

4.1.2でのみ発生していたバグのようです。


Use a better test description

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

テストメソッド名を、より分かりやすい名前に修正しています。


Merge pull request #15772 from nbudin/sti_through_bug

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

through_scope_attributesメソッドでインヘリタンスカラムを追加しないよう修正しています。

こちらも4.1.2でのみ発生していたバグのようです。


'TextHelper#highlight' now accepts a block to highlight the matched words.

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

highlightがブロックを受け付けるようになりました。

highlight('You searched for: rails', 'rails') { |match| link_to(search_path(q: match, match)) }
# => You searched for: <a href="search?q=rails">rails</a>

便利。


Introduce an object to aid in creation and management of @attributes

ActiveRecordの修正です。

@attributesの管理の為のAttributeSetクラスを新規に作成しています。


Merge pull request #15450 from aditya-kapoor/remove-nbsp-debug

ActionView::Helpers#debugメソッドの修正です。

&nbsp;の置換処理を削除しています。デバッグツールで見た際に、&nbsp;が無くても問題無い為、との事。


ErrorsController shouldn't inherit ApplicationController, but ActionController::Base

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

exampleが誤っていたのを修正しています。


Merge pull request #15747 from sgrif/sg-trolololol-this-is-so-broken

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

レコードが追加された際、必ずオンメモリのカウンターキャッシュの値も更新するよう対応しています。


Merge pull request #15728 from sgrif/sg-double-save-hm-t

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

has_many :through associationsを使用している、かつ、after_createコールバックを定義している場合に、2回レコードのsaveが実行されていたらしく、2回実行されないよう修正しています。


add both branches to the only_path conditional

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

options[:only_path]が定義されてるかどうかで処理を分岐するよう修正しています。処理自体は変わってないように見えるので、わかりやすくする為のリファクタリングかなあ。


Remove extra list item element

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

不要な*の削除です。一つしか要素が無かったので、リストでは無くしています。


Merge pull request #15537 from tgxworld/fix_state_leak

ActionPackのテストの修正です。

includeの削除・追加の調整をしています。


Merge pull request #15809 from maurogeorge/guides-console-app

rails guideのThe Rails Command Lineの修正です。

The app and helper objectsの項を追加しています。

コマンドライン上でhelperメソッドを呼び出す方法について説明を追加しています。

>> app.root_path
=> "/"

>> app.get _
Started GET "/" for 127.0.0.1 at 2014-06-19 10:41:57 -0300
>> helper.time_ago_in_words 30.days.ago
=> "about 1 month"

>> helper.my_custom_helper
=> "my custom helper"

app.root_pathのやり方が最初分からず、調べるの苦労した覚えが…。


docs, configurations method is listed in the docs. [ci skip]

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

:singleton-method:の記述を削除しています。不要との事。


Make dependencies.rb add a name to NameError

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

存在しない定数を指定した際に起きるNameErrornameの値を設定するよう修正しています。

e = assert_raise(NameError) { A::DoesNotExist.nil? }
assert_equal "uninitialized constant A::DoesNotExist", e.message
assert_equal "A::DoesNotExist", e.name

こんな感じで、使用とした定数名が取得出来るようになっています。