2015/02/19分のコミットです。
CHANGELOGにのったコミットは以下の通りです。
- Add
time
option to#touch
- Add ActiveRecord::Base.suppress to prevent the receiver from being saved during the given block.
activemodel/CHANGELOG.md
- Deprecate
ActiveModel::Errors#get
,ActiveModel::Errors#set
andActiveModel::Errors#[]=
methods that have inconsistent behaviour. - Deprecate
ActiveModel::Errors
add_on_empty
andadd_on_blank
methods
activerecord/lib/active_record/persistence.rb
の修正です。
touch
メソッドに、任意の時刻を設定出来るようにする為のtime
オプションを追加しています。
user.touch(time: Time.new(2015, 2, 1, 0, 0, 0)) # UPDATE "users" SET "updated_at" = '2015-01-31 15:00:00' WHERE "users"."id" = ? [["id", 4]]
Track Gemfile.lock at the repository
.gitignore
、.travis.yml
の修正です。バージョン管理にGemfile.lock
を追加しています。
メインの理由は、bitsectをよりやりやすくする為で、テストが失敗した時、その時に使用していたgemの詳細(コミット番号等)がわかった方が調査がしやすいだろう、という事で追加したようです。バージョンだけならまだしも、コミット番号は確かに。
Revert "Merge pull request #18951 from jurezove/gemfile-lock-to-plugin-gitignore-template"
rails plugin用のgitignoreテンプレートにGemfile.lock
を追加したコミットをrevertしています。
先のコミットであったように、エラー調査とうの事を考えると、Gemfile.lock
はバージョン管理されてた方が良いのでは無いか、という事でrevertしています。
Talk about Gemfile.lock in the contributing guide
rails guideのContributing to Ruby on Rails
の修正です。
Gemfile.lock
の取り扱いについての説明を追記しています。
Merge pull request #15700 from maurogeorge/guides-local_assigns
actionview/lib/action_view/template.rb
、guides/source/layouts_and_rendering.md
の修正です。
local_assigns
の使い方について、API doc、rails guideそれぞれに説明を追加しています。
Improve documentation of local_assigns
actionview/lib/action_view/template.rb
のdocの修正です。
先のコミットで追加されたlocal_assigns
のAPI docの改善(説明の追加、docの位置を適切な箇所に移動)を行っています。
Add nodoc to private constant [ci skip]
actionview/lib/action_view/template.rb
の修正です。
private constantに:nodoc:
を追加しています。
Merge pull request #18634 from morgoth/deprecate-some-errors-methods
activemodel/lib/active_model/errors.rb
の修正です。
ActiveModel::Errors#get
、ActiveModel::Errors#set
、ActiveModel::Errors#[]=
メソッドをdeprecateにしています。
今後は、errors.messages
を直接操作するように、との事です。
errors.messages[:foo] = "omg" errors.messages[:foo]
そもそもget
の挙動がおかしく、get
の挙動を直すまでもなく、直接messages
を参照すればよいだろう、という事でdeprecateになったようです。
Merge pull request #18393 from y-yagi/fix_mailer
Mailer Generatorの修正です。
generatorでmailerを生成する際、_mailer
サフィックスを自動で付与する 、という対応があったのですが、テスト用のファイルからサフィックスの削除の対応が漏れていたのと、viewにも"mailer"サフィックスが付与さされてなかったので、viewにも"mailer"サフィックスが付与されるよう修正しています。
Merge pull request #18411 from todd/extract_record_tag_helper
ActionView::Helpers::RecordTagHelper
moduleを外部gem(record_tag_helper
)に切り出しています。
RecordTagHelper
で提供されていたメソッド(div_for
、content_tag_for
)を使用したい場合、別途record_tag_helper
gemを追加する必要があります。
DHHのコメントを見る限り、RecordTagHelper
は実験的に追加したものの、実際は使わなかったので、coreから出しちゃえ―という感じようです。
Merge pull request #18917 from lautis/non-string-csrf-token
actionpack/lib/action_controller/metal/request_forgery_protection.rb
の修正です。
authenticity_token
にString以外の値(Hash等)を指定した場合に、NoMethodError
が起きてしまっていたのを修正しています。
例。
{"authenticity_token": {"foo": "bar"}}
valid_authenticity_token?
メソッド内でBase64.strict_decode64
を呼び出しており、そこでNoMethodError
が起きてしまっていたので、rescue
の対象にNoMethodError
を追加し、対応しています。これは次のコミットでまた修正されています。
actionpack/lib/action_controller/metal/request_forgery_protection.rb
の修正です。
valid_authenticity_token?
メソッドの第二引数のencoded_masked_token
がStringクラスでがどうかメソッドの先頭でチェックし、Stringでない場合、直ぐreturn false
するよう修正しています。
Base64.strict_decode64
メソッドの例外処理で、NoMethodError
が起こらないようにするのようです。
Reduce the number of times #clean_path_info
is called
actionpack/lib/action_dispatch/middleware/static.rb
の修正です。
match?
メソッドでclean_path_info
メソッドの呼び出し回数を減らすようリファクタリングしています。
+ path = Rack::Utils.clean_path_info path - paths = [path, "#{path}#{ext}", "#{path}/index#{ext}"].map { |v| - Rack::Utils.clean_path_info v - } + paths = [path, "#{path}#{ext}", "#{path}/index#{ext}"]
Freeze strings to reduce allocations in integration tests
actionpack/lib/action_dispatch/middleware/request_id.rb
の修正です。
RequestId
クラス内で使用している文字列を凍結状態にしています。object allocations削減の為との事。
+ X_REQUEST_ID = "X-Request-Id".freeze # :nodoc: + ACTION_DISPATCH_REQUEST_ID = "action_dispatch.request_id".freeze # :nodoc: + HTTP_X_REQUEST_ID = "HTTP_X_REQUEST_ID".freeze # :nodoc: +
変更前の生成数が1030722で、変更後が967722との事。結構違いますねえ。
Allow Rack::Runtime to be deleted from middleware stack.
railties/lib/rails/configuration.rb`の修正です。
何かmiddlewareをdeleteした後に、その削除したmiddlewareをinsert_before
、insert_after
メソッドに指定した場合に、No such middleware
エラーが発生するバグがあったのを修正しています。
Remove unused gsub_app_file method from Bukkit.
railties/test/isolation/abstract_unit.rb
の修正です。
使用していないBukkit#gsub_app_file
メソッドを削除しています。
Should handle array option for :cast_as
activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
の修正です。
配列型を使用している場合に、cast_as
オプションの値が適用されないバグがあったのを修正しています。
Use delegate
to call the methods to @conn
activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb
の修正です。
@conn
のメソッドを呼び出しているだけのメソッドについては、delegate
メソッドを使用するよう修正しています。
Handle array option in type_to_sql
activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
の修正です。
type_to_sql
メソッドの引数にarray
オプションを追加して、配列型を指定された場合の対応を追加しています。
Extract precision from datetime and time columns
activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
、
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
の修正です。
datetime
、time
カラムからprecision
オプションを取り除くよう修正しています。
Merge pull request #18910 from perceptec/add_suppressor
ActiveRecordの修正です。
save処理を発生させないようにする事が出来るActiveRecord::Suppressor
moduleを新規に追加しています。
例えば、何かコメントを作成した場合に、そのコメントについての通知を送る、という処理があったとします。
class Comment < ActiveRecord::Base belongs_to :commentable, polymorphic: true after_create -> { Notification.create! comment: self, recipients: commentable.recipients } end
上記例のようにafter_create
callbackでNotification
の作成を行う事により、コメントの作成時に必ず通知処理も作成される、という処理が行えます。
ただ、通常の場合は上記で問題無いのですが、イレギュラー処理(コメントのデータをコピーする、など)の場合に、Comment
は作成するけど、Notification
は作りたく無い、という事があります。その場合に、今回コミットされた、ActiveRecord::Suppressor
を使うと、Notification
の作成を抑制する事ができます。
module Copyable def copy_to(destination) Notification.suppress do # この間で`Comment`の作成処理が行われても、`Notification`の作成処理は行われない end end end
これは割と使いそう。
Copy edit the suppressor documentation
ActiveRecord::Suppressor
関連のdocの整理(スペースの追加、:nodoc:の追加等)を行っています。
Return true instead of self when suppressed
activerecord/lib/active_record/suppressor.rb
の修正です。
save!
処理を抑止した際に、true
を返すよう修正しています。
Do not mutate the operations array
railties/lib/rails/configuration.rb
の修正です。
merge_info
メソッドで、配列の結合にconcat
メソッドを使用していたのを、+
を使用するよう修正しています。concat
だとレシーバー自身を変更してしまう為。
Deprecate ActiveModel::Errors
add_on_empty
and add_on_blank
methods
activemodel/lib/active_model/errors.rb
の修正です。
ActiveModel::Errors#add_on_empty
、ActiveModel::Errors#add_on_blank
をdeprecateにしています。
先にコミットされたActiveModel::Errors#get
, ActiveModel::Errors#set
ActiveModel::Errors#[]=
がdeprecateになった為、こちらも合わせてdeprecateにしたようです。
Fix code sample for custom exception handler [ci skip]
rails guideのRails Internationalization (I18n) API
の修正です。
Using Different Exception Handlers
の項で、exampleの中のエラークラス名に誤りがあったのを修正しています。