2016/04/21分のコミットです。
CHANGELOGにのったコミットは以下の通りです。
Merge pull request #23557 from kamipo/dump_indexes_in_create_for_generates_sql_in_one_query
Acitve Recordの修正です。
schemaファイルを生成する際、indexの生成にadd_index
メソッドを使用するようになっていたのを、create_table
内でindex
メソッドを使用するよう修正しています。
# before ActiveRecord::Schema.define(version: 20160419063525) do create_table "events", force: :cascade do |t| t.string "name", limit: 5 t.datetime "created_at", null: false t.datetime "updated_at", null: false end add_index "events", ["name"], name: "index_events_on_name" end
# after ActiveRecord::Schema.define(version: 20160419063525) do create_table "events", force: :cascade do |t| t.string "name", limit: 5 t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["name"], name: "index_events_on_name" end end
体裁が整いこちらの方が見やすいだろう、というのと、MySQLの場合はこれにより不要なindex設定のクエリーが実行されない(create tableのqueryでindexの設定も行える為)というメリットがあるため、との事です。
- [ci skip] regardless
is usually followed by of
and not by if .. or not
.
activemodel/lib/active_model/conversion.rb
のdocの修正です。
ActiveModel::Conversion#to_key
メソッドのグラマーの修正を行っています。
Merge pull request #24221 from gregmolnar/uuid
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
の修正です。
create_join_table
メソッドのcolumn_options
オプションに、primary keyの型を指定出来るよう対応しています。
create_join_table :artists, :musics, column_options: { type: :uuid }
activesupport/lib/active_support/core_ext/object/blank.rb
の修正です。
String#blank?
の空白チェック用の正規表現の見直しを行っています。
BLANK_RE = /\A[[:space:]]*\z/ def blank? - # 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 + # Regex check is slow, only check non-empty strings. + # A string not blank if it contains a single non-space string. + empty? || !(/[[:^space:]]/ === self) end
文字列が全て空かどうかではなく、文字列中に空じゃない文字があるかどうか、でチェックするようにしたんですねえ。こちらの方が高速との事です。コミットログにあったベンチマークは以下の通りです。
require 'benchmark/ips' def string_generate str = " abcdefghijklmnopqrstuvwxyz\t".freeze str[rand(0..(str.length - 1))] * rand(0..23) end strings = 100.times.map { string_generate } ALL_WHITESPACE_STAR = /\A[[:space:]]*\z/ Benchmark.ips do |x| x.report('current regex ') { strings.each {|str| str.empty? || ALL_WHITESPACE_STAR === str } } x.report('+ instead of * ') { strings.each {|str| str.empty? || /\A[[:space:]]+\z/ === str } } x.report('not a non-whitespace char') { strings.each {|str| str.empty? || !(/[[:^space:]]/ === str) } } x.compare! end # Warming up -------------------------------------- # current regex # 1.744k i/100ms # not a non-whitespace char # 2.264k i/100ms # Calculating ------------------------------------- # current regex # 18.078k (± 8.9%) i/s - 90.688k # not a non-whitespace char # 23.580k (± 7.1%) i/s - 117.728k # Comparison: # not a non-whitespace char: 23580.3 i/s # current regex : 18078.2 i/s - 1.30x slower
rails guideのAutoloading and Reloading Constants
の修正です。
Top-Level Constants
及びQualified References
の項のグラマーの修正を行っています。
activesupport/lib/active_support/core_ext/object/blank.rb
の修正です。
先のString#blank?
の空白チェック用の正規表現の見直しを行った対応により不要になったBLANK_RE
定数を削除しています。
Update delegate to use newer Ruby syntax
activesupport/lib/active_support/core_ext/module/delegation.rb
の修正です。
delegate
メソッドの引数の指定に、キーワード引数を使用するよう修正しています。
add doc for :type
option of #create_join_table
[ci skip]
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
のdocの修正です。
create_join_table
メソッドのdocに:type
オプションについての説明を追加しています。
が、オプションを説明する箇所に誤りがあり、後ほどrevertされています。
Revert "add doc for :type
option of #create_join_table
[ci skip]"
という訳で、直前の修正をrevertしています。
Merge pull request #24657 from maclover7/fix-23643-1
rails guideのRuby on Rails 5.0 Release Notes
の修正です。
ActionDispatch::IntegrationTest
及びActionController::TestCase
のHTTP request methodsの引数をキーワード引数を指定出来るようにした対応(Use kwargs in ActionController::TestCase and ActionDispatch::Integration HTTP methods by kirs · Pull Request #18323 · rails/rails)について、Deprecations
の項にentryを追加しています。
restores code comments in String#blank? [ci skip]
activesupport/lib/active_support/core_ext/object/blank.rb
のdocの修正です。
String#blank?
メソッドのコード内に、処理内容についての説明のコメントを追加しています。
activerecord/lib/active_record/associations.rb
のdocの修正です。
has_many
のdoc内のCollection associations
項のタイトル部分に、スペースを追加しています。
Merge pull request #24664 from y-yagi/use_wrapper_file_to_add_rake_task_for_engines
railties/lib/rails/generators/rails/plugin/templates/Rakefile
の修正です。
rails engine用のRakefileで、gem用のリリースタスクを追加するのにBundler::GemHelper.install_tasks
メソッドを直接呼び出していたのを、bundlerが提供しているラッパーファイル(bundler/gem_tasks
)を使用するよう修正しています。bundler側で何かtaskを追加した場合に、Rakefileを修正せずにそのtaskを使用する事が出来る為。
Merge pull request #24661 from maclover7/fix-22975
actionpack/lib/action_controller/renderer.rb
の修正です。
ActionController::Renderer.for
メソッドの第二引数のdefaultsのデフォルト値に、DEFAULTS
定数を使用しているのですが、その値を設定する際にdup
した値を使用するよう修正しています。
# Create a new renderer instance for a specific controller class. - def self.for(controller, env = {}, defaults = DEFAULTS) + def self.for(controller, env = {}, defaults = DEFAULTS.dup) new(controller, env, defaults)
DEFAULTS
はfreezeしているので、そのまま値を使用すると、ApplicationController.renderer.defaults.merge!
を使用した際にエラーになってしまう為、対応したとの事です。