なるようになるブログ

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

rails commit log流し読み(2018/05/23)

2018/05/23分のコミットです。

CHANGELOGへの追加はありませんでした。


Merge pull request #32931 from jeremyevans/fast-xor

actionpack/lib/action_controller/metal/request_forgery_protection.rbの修正です。

ActionController::RequestForgeryProtection#xor_byte_stringsメソッドをリファクタリングしています。

ループ数やpackメソッドの呼び出しを削減し、1.7倍程度高速になっているとの事です。


Merge pull request #32934 from aki77/fix-locale-selector

railties/lib/rails/templates/rails/mailers/email.html.erbの修正です。

email previewでlocaleを変更した際に、subjectが変更されないバグがあったのを修正しています。


Remove 7 years old note-to-self by tenderlove

actionpack/lib/action_dispatch/journey/nfa/simulator.rbのdocの修正です。

Simulator#simulateメソッドから不要なコメントを削除しています。


Rollback parent transaction when children fails to update (#32796)

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

autosave associationsを使用している場合に、子のassociationsの保存に失敗した場合、親associationのtransactionをrollbackするよう修正しています。


Bump minimum version of Thor to 0.19.0

railties/railties.gemspecの修正です。

dependencyに指定するThorのminimum versionの指定を0.18.1から0.19.0に更新しています。

Thor 0.18だとfrozen string literalを指定している場合に、コマンド実行時にFrozenErrorが発生してしまうという問題がある為。


Indicate true in a doc comment is code-like.

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

CacheHelper#cache_fragment_nameメソッドのdoc内のskip_digestオプションについて説明している箇所で、オプションのkeyだけが等幅フォントで表示されていたのを、value等幅フォントで表示されるよう修正しています。


Merge pull request #32144 from kazu9su/master

activestorage/test/service/disk_service_test.rbの修正です。

ActiveStorage::Service::DiskService#url_for_direct_uploadメソッドについてのテストを追加しています。


Merge pull request #32851 from yskkin/doc_require_dependency

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

require_dependencyメソッドがAPI docに表示されるよう修正しています。

require_dependencyは既にRails guideで紹介されており、publc API扱いの為。


Merge pull request #32699 from printercu/patch-3

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

yarn:install taskで./bin/yarnを実行する際に、NODE_ENVを指定するよう修正しています。

環境変数NODE_ENVが指定されていればその値を、なければRAILS_ENVを見に行くようになっています。


Merge pull request #32822 from lxxxvi/improved_error_message_in_assert_changes

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

assert_changesメソッドでassertionでエラーになった際のメッセージを修正しています。

expected / actualが明確にわかるようになっています。

# before
"value" didn't change to y

# after
"value" didn't change to as expected
Expected: "y"
  Actual: "z"

Fix RDoc formatting: + doesn't work with space [ci skip]

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

CacheHelper#cache_fragment_nameメソッドのdoc内のskip_digestオプションが正しく等幅フォントで表示されていなかったのを修正しています。

rails commit log流し読み(2018/05/22)

2018/05/22分のコミットです。

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

activesupport/CHANGELOG.md

ctivestorage/CHANGELOG.md


Merge pull request #32523 from kaspth/enumerable-index-with-extension

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

Enumerable moduleにindex_withメソッドを追加しています。

index_withはenumerableの値をkeyとしたHashを生成する事が出来ます。Hashのkeyはblockで指定、又は、メソッドの引数で指定出来ます。

post = Post.new(title: "hey there", body: "what's up?")
%i( title body ).index_with { |attr_name| post.public_send(attr_name) }
# => { title: "hey there", body: "what's up?" }

%i( title body ).index_with(nil)
# => { title: nil, body: nil }

Merge pull request #32936 from jacobsmith/image-variant-allow-disabling-options

activestorage/app/models/active_storage/variation.rbの修正です。

variantに渡す引数にfalse、または、nilを指定した場合、そのオプションをprocessorに渡さないよう修正しています。

例えば、avatar.variant(monochrome: false)とした場合、monochromeオプションは渡されなくなります。


Disable foreign keys during alter_table for sqlite3 adapter

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

sqlite3 adapterでalter_tableを実行する際に外部キー制約を無効化するよう修正しています。

sqlite3ではalter_tableを実行する際、変更後のschema及び元のデータをコピーし一時テーブルを作成、そして元のテーブルを削除し、最後に一時テーブルを元のテーブルにリネーム、というような流れで処理が行われます。

で、外部キー制約が設定されたままだと、そのテーブルの削除処理でエラーになってしまう為、処理中は外部キー制約を無効化するよう修正しています。


Allow Range#=== and Range#cover? on Range

Active Supportの修正です。

元々Range#===はRange#include?メソッドを使ってチェックを行っていたのですが、これをcover?`を使うようRuby側で変更が行われました(コミット)。

で、この影響でRuby 2.6でRange#===の挙動が変わってしまっていたのを修正しています(Range#cover?を追加して対応しています)。

参考:Feature #14575: Switch Range#=== to use cover? instead of include?


add CHANGELOG/Doc

activesupport/CHANGELOG.md、及び、Rails guideのActive Support Core Extensionsの修正です。

先のRangeの対応についてCHANGELOGにエントリーを追加、及び、guideに説明を追加しています。

rails commit log流し読み(2018/05/21)

2018/05/21分のコミットです。

CHANGELOGへの追加はありませんでした。


SqlTypeMetadata is :nodoc: class [ci skip]

activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rbの修正です。

内部向けのクラスであるPostgreSQLTypeMetadataAPI docに表示されないよう修正しています。


Bump minimum SQLite version to 3.8

Active Recordの修正です。

サポートするSQLiteのバージョンを3.8以上に修正しています。

macOS 10.10やUbuntu 14.04ではSQLite 3.8がデフォルトでインストールされていること、また、3.8以上をサポートする事でmulti insertが使用出来るか等の幾つかの機能のチェック処理を削除出来ることから、サポートバージョンを修正しています。


Enable Lint/StringConversionInInterpolation rubocop rule

Lint/StringConversionInInterpolation copを有効にして、各ファイルにcopを適用しています。


Exception wording change

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

polymorphic associationに対してreflection.klassを取得しようとした場合に表示するエラーメッセージのグラマーを修正しています。

rails commit log流し読み(2018/05/20)

2018/05/20分のコミットです。

CHANGELOGへの追加はありませんでした。


Add test case that configure config.action_view.finalize_compiled_template_methods

railties/test/application/configuration_test.rbの修正です。

ActionView::Template.finalize_compiled_template_methodsがconfig経由で指定出来ることを確認するテストを追加しています。

rails commit log流し読み(2018/05/19)

2018/05/19分のコミットです。

CHANGELOGへの追加はありませんでした。


Raise a better exception when a invalid depreation behavior is set

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

ActiveSupport::Deprecation.behaviorに不正な値を指定した場合に、ArgumentErrorをraiseして適切なエラーメッセージを表示するよう修正しています。


Merge pull request #32900 from ttanimichi/app-update-skip-yarn

railties/lib/rails/app_updater.rbrailties/lib/rails/generators/rails/app/app_generator.rbの修正です。

app:updateタスクで、bin/yarnが存在しない場合にyarnに関連するコンテンツを生成しないよう修正しています。


Finalize transaction record state after real transaction

activerecord/lib/active_record/connection_adapters/abstract/transaction.rbactiverecord/lib/active_record/transactions.rbの修正です。

実際のtransactionが完了してから、recordのtransaction stateを確定するよう修正しています。

元の実装だとtransactionがrollbackしたのに、recordが作成済み(new_record?が誤った値を返す)と判断されてしまうバグがあった為。


Rollback correctly restore initial record id after double save

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

transactionの中でsaveを複数回実行した場合に、rollback時にidが元の値に戻らないバグがあったのを修正しています。

rails commit log流し読み(2018/05/18)

2018/05/18分のコミットです。

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

activestorage/CHANGELOG.md


Merge pull request #32908 from anniecodes/fix-time-random-string

activemodel/lib/active_model/type/time.rbの修正です。

time型のattributeに不正なStringを指定した場合に、値に2000-01-01 00:00:00が設定されてしまっていたのを、nilが設定されるよう修正しています。

# before
user = User.new
user.time_of_birth = "ABC"
user.time_of_birth # => Sat, 01 Jan 2000 00:00:00 UTC +00:00

# after
user = User.new
user.time_of_birth = "ABC"
user.time_of_birth # => nil

Generate getter and setter methods in mixin

activestorage/lib/active_storage/attached/macros.rbの修正です。

attachmentに対するgetter / setterメソッドを定義する際に、generated_association_methodsメソッドで生成されたmoduleに対してメソッドを定義するよう修正しています。

メソッドを定義するclassでメソッドをオーバーライド出来るようにするため。

例えば、Userに対してavatarというattachmentがあった場合、

User.class_eval do
  def avatar
    super.filename.to_s.reverse
  end
end

上記のようにすると、Userに定義されたavatarメソッドが呼ばれるようになります。


Fix markdown [ci skip]

rails guideのActive Storage Overviewの修正です。

コードを挿入する際のバッククオートの数が多かった(三つではなく四つあった)のを修正しています。


Permit opening a blob in a custom tempdir

Active Storageの修正です。

blobをopenする際のtempdirをメソッドの引数で指定出来るよう修正しています。


Fix documentation for ActionController::Params#fetch

actionpack/lib/action_controller/metal/strong_parameters.rbのdocの修正です。

ActionController::Params#fetchメソッドのdocに、指定されたkeyが見つからなかった場合、第二引数に指定された値がそのまま返ってくる旨説明されていました。

が、実際は、そのままではなく、ActionController::Parametersに変換された値が返ってくるケースがあったため、その旨説明を修正しています。

rails commit log流し読み(2018/05/17)

2018/05/17分のコミットです。

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

activestorage/CHANGELOG.md


Add ActiveStorage::Blob#open

Active Storageの修正です。

ActiveStorage::Blob#openメソッドを追加しています。

openメソッドはblobをディスクに一時ファイルとして保存し、そのファイルに対して処理を実行出来るようになっています。

例。

message.video.open do |file|
  system '/path/to/virus/scanner', file.path
  # ...
end

合わせて、元々上記のような用途で使う想定だったActiveStorage::Downloading moduleをdeprecateにしています。


Demonstrate ActiveStorage::Blob#open in the Active Storage guide

rails guideのActive Storage Overviewの修正です。

guideにActiveStorage::Blob#openを使った場合のexampleを追加しています。


Add missing block parameters

activestorage/lib/active_storage/analyzer.rbactivestorage/lib/active_storage/previewer.rbの修正です。

メソッドの引数指定に誤りがあった箇所があったのを修正しています。


Add ActiveStorage::Previewer#tempdir

activestorage/lib/active_storage/previewer.rbの修正です。

ActiveStorage::Previewertempdirメソッドを追加しています。元々はActiveStorage::Downloadingtempdirメソッドを使うようになっていたのですが、ActiveStorage::Downloadingがdeprecateになったため、独自にメソッドを定義するようにしています。


Remove unused require "active_support/core_ext/string/filters"

activestorage/lib/active_storage/previewer.rbの修正です。

使用していないactive_support/core_ext/string/filtersのrequireを削除しています。


Active storage: Image variant options not correct

activestorage/app/models/active_storage/variant.rbのdocの修正です。

ctiveStorage::Variant classのdoc内、画像変換に指定するオプションに誤りがあったのを修正しています。


Fix formatting of author credit [ci skip]

activestorage/CHANGELOG.mdの修正です。

ActiveStorage::Blob#openメソッドを追加した対応のエントリーの、author部分のフォーマットを修正しています。