なるようになるブログ

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

rails commit log流し読み(2015/03/01)

2015/03/01分のコミットです。

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

railties/CHANGELOG.md


Merge pull request #18965 from hjoo/rake_restart

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

rake restartタスクを追加しています。中身はtmp/restart.txttouchしているだけです。


[ci skip] Update documentation for Range#to_formatted_s

activesupport/lib/active_support/core_ext/range/conversions.rbのdocの修正です。

Range#to_formatted_sメソッドのdocに、exampleを追加及び独自のformatを追加する方法についての説明を追加しています。


[ci skip] Fix to String

rails guideのActive Support Core Extensionsの修正です。

to_queryメソッドのexampleで、出力例の部分をクォートされてなかったのを修正しています。


[ci skip] Fix to comment

rails guideのActive Support Core Extensionsの修正です。

String#removeメソッドのexampleの出力例のコメントの箇所に#が無かったのを追加しています。


Reduce allocated memory for Module#delegate.

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

Module#delegateメソッドで、メモリ割り当てを削減するよう改善しています。

-    file, line = caller.first.split(':', 2)
+    file, line = caller(1, 1).first.split(':', 2)

テストスクリプトは以下。

require 'test_helper'

class DocumentsIntegrationTest < ActionDispatch::IntegrationTest
  test "create" do
    post '/documents', params: { document: { title: "New things", content: "Doing them" } }

    document = Document.last
    assert_equal 'New things', document.title
    assert_equal 'Doing them', document.content
  end
end

report = MemoryProfiler.report do
  Minitest.run_one_method(DocumentsIntegrationTest, 'test_create')
end

report.pretty_print

実行結果。

# before
allocated memory by gem
-----------------------------------
activesupport/lib x 486470

allocated memory by file
-----------------------------------
/home/guoxiang/work/rails-dev-box/rails/activesupport/lib/active_support/core_ext/module/delegation.rb x 195005

allocated memory by location
-----------------------------------
/home/guoxiang/work/rails-dev-box/rails/activesupport/lib/active_support/core_ext/module/delegation.rb:170 x 136119
# after
llocated memory by gem
-----------------------------------
activesupport/lib x 354170

allocated memory by file
-----------------------------------
/home/guoxiang/work/rails-dev-box/rails/activesupport/lib/active_support/core_ext/module/delegation.rb x 62705

allocated memory by location
-----------------------------------
# Does not show in report

[ci skip] Add code examples for Module#anonymous? documentation

activesupport/lib/active_support/core_ext/module/anonymous.rbのdocの修正です。

Module#anonymous?メソッドのdocにexampleを追加しています。


drop allocations when handling model url generation

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

Stringオブジェクトの生成処理を減らすよう修正しています。

-          named_route = prefix + "#{name}_#{suffix}"
+          named_route = "#{prefix}#{name}_#{suffix}"

Minor fixes (proposal)

activejob/README.mdの修正です。

Sending -> sendingAPI documentation is at -> API documentation is at:にそれぞれ修正しています。


Update link (minor fix)

guides/Rakefileの修正です。

kindlegenのリンクを http://www.amazon.com/kindlepublishing -> http://www.amazon.com/gp/feature.html?docId=1000765211に修正しています。


[ci skip] Fix fenced code block lang

rails guideのForm Helpersの修正です。

Basic Structuresの項のexampleのmarkdownの言語の設定をerb -> rubyに修正しています。


Fix segmentation fault in ActionPack tests

actionpack/test/dispatch/response_test.rbの修正です。

rails本体のバグ(Segfault from keyword rest arg when coercing an object that defines to_hash)の影響でsegmentation faultしてしまうActionPackのテストがあったのを修正しています。

args + kwargsの組み合わせでセグフォルしてしまうようです。

例。

def foo(*args, **kwargs)
  puts "args: #{args}"
  puts "kwargs: #{kwargs}"
end

foo('foo' => 'bar')

とりあえずテストのコードの方を修正しています。


Lines of code can be 100,000+ in a Rails app

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

5桁までしか出力する事を想定してなかったrake statsを、コードの行数が6桁以上の場合でも崩れず表示されるよう修正しています。


[ci skip] Add .

rails guideのRuby on Rails 4.0 Release Notesの修正です。

Major Featuresの一覧で行の最後にピリオドが無い箇所があったのを追加しています。