なるようになるブログ

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

rails commit log流し読み(2014/11/29)

2014/11/29分のコミットです。

CHANGELOGへの追加はありませんでしたが、Rails 4.2.rc1のリリースに伴い、4-2-stableブランチにが作成され、 masterブランチはRails 5向けの開発がスタートしています。


Start Rails 5 development :tada:

.travis.ymlRAILS_VERSION、各CHANGELOGの修正です。

Rails 5の開発開始、という事でrailsのバージョンを5.0.0.alphaに修正、古いCHANGELOGの削除、 また、rails 5ではRuby1.9系はサポートしないので、travisの対象から1.9系、2.0.0を削除しています。

rails 5はRuby 2.2以上を対象とする予定ですが、まだ2.2が正式リリースされてないので、当面は2.1を対応とする予定のようです。


We don't need to use sass-rails 5.0.0.beta

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

使用するsass-railsのバージョンを'~> 4.0'に修正しています。


Use jquery-rails master to resolve dependencies

Gemfileの修正です。

jquery-railsのmaterを使用するにように修正、及びdelayed_job_active_recordコメントアウトしています。

delayed_job_active_recordはまだRails5では使用出来ないとの事です。


fixed indent of end in jdom.rb

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

インデントがスペース1つになっている箇所があったので修正しています。


Prevent Numeric#to_s from allocating an array

activesupport/lib/active_support/core_ext/big_decimal/conversions.rbactivesupport/lib/active_support/core_ext/numeric/conversions.rbの修正です。

Numeric#to_sメソッドでArrayの生成を避けるようリファクタリングしています。


Allow failures with Active Job

.travis.ymlの修正です。

ActiveJobのテストがコケるのをtravisで許容するよう修正しています。

ちょっと不安定なようです。依存しているgemが多いからですかねえ。


Allow failures with Active Job integration tests

.travis.ymlの修正です。

ActiveJobのintegrationテストがコケるのもtravisで許容するよう修正しています。


[ci skip] fix class name

rails guideのRails Internationalization (I18n) APIの修正です。

18n::InvalidPluralizationData -> I18n::InvalidPluralizationDataに修正しています。


Remove a reference to Ruby 1.9 in Guides

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

String#fromメソッドのexampleでRuby 1.9系の場合の説明があったのですが、削除しています。


Bump required Ruby version to 2.1.0

コンポーネントのgemspecの修正です。

required_ruby_versionを2.1.0以上に修正しています。


adds missing period in test.rb [ci skip]

railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.ttの修正です。

test_orderについて説明しているコメントにピリオドが無かったのを追加しています。


Pass symbol as an argument instead of a block

メソッドの引数にブロックではなくsymbolを渡せる箇所については、symbolを渡すよう修正しています。

サンプル抜粋。

-        if m.attachments.detect { |a| a.inline? }
+        if m.attachments.detect(&:inline?)

PRに性能測定の結果があったので、引用。

require 'benchmark/ips'

def block
  (1..100).map{|i| i.to_s}
end

def to_proc
  (1..100).map(&:to_s)
end

Benchmark.ips do |x|
  x.report('block')   { block   }
  x.report('to_proc') { to_proc }
end
# Ruby 2.1.2p95

block 46707.3 (±7.8%) i/s - 235768 in 5.079617s
to_proc 55143.5 (±7.2%) i/s - 276554 in 5.040752s

# Ruby 2.0.0p481

block 33271.0 (±6.8%) i/s - 168646 in 5.093196s
to_proc 37346.0 (±7.6%) i/s - 188870 in 5.087220s

# Ruby 1.9.3p545

block 31478.7 (±11.3%) i/s - 156876 in 5.056661s
to_proc 39219.9  (±7.2%) i/s - 195210 in 5.004236s

因みに、blockの早いケースもあるようです。

require 'benchmark/ips'

class Foo
  def initialize
    @a, @b, @c, @d, @e, @f, @g, @h, @i = 1, 2, 3, 4, 5, 6, 7, 8, 9
  end
end

@foo = Foo.new

Benchmark.ips do |x|
  x.report('block') {
    @foo.instance_variables.map { |var| var.to_s }
  }
  x.report('to_proc') {
    @foo.instance_variables.map(&:to_s)
  }
  x.compare!
end
Calculating -------------------------------------
               block     26506 i/100ms
             to_proc     25584 i/100ms
-------------------------------------------------
               block   353692.8 (±14.3%) i/s -    1749396 in   5.057290s
             to_proc   384096.3 (±12.8%) i/s -    1893216 in   5.020770s

Comparison:
             to_proc:   384096.3 i/s
               block:   353692.8 i/s - 1.09x slower

Pure rack apps can be mounted with a name

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

ActionDispatch::Routing::Mapper::Base#mountメソッドに、rails以外のrackアプリを指定した場合、asオプションが無視されてしまうリグレッションがあったのを修正しています。