なるようになるブログ

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

rails commit log流し読み(2019/09/08)

2019/09/08分のコミットです。

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


Class#new also separates keyword arguments and optional hash

Class#newがキーワード引数とoptional hashを分離するようになった為、それぞれ別に渡すよう修正しています。

が、これだとRuby 2.6以下だと期待通りに動作しない為、後ほどRevertしています。


Handle kwargs only in Ruby >= '2.7'

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

Include kwargs definition in the generated method signatures and method callsのリトライとして、Ruby 2.7以上の場合のみattribute methodsでキーワード引数を受け取れるよう修正しています。


Revert "Class#new also separates keyword arguments and optional hash"

キーワード引数とoptional hashを別に渡すよう修正した、Class#new also separates keyword arguments and optional hashをRevertしています。


rubocop

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

rubocopの設定に違反している箇所があったのを修正しています。


Merge pull request #37153 from eugeneius/marshal_inspected_records

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

parameterのfilterに使われるクラスを無名クラスから通常のクラスに変更しています。無名クラスだとMarshalした際にエラーになってしまう為。

rails commit log流し読み(2019/09/07)

2019/09/07分のコミットです。

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


Passing in a Hash instance as kwargs parameters requires the "double splat" prefix

Active Storageの修正です。

Hashをキーワード引数として渡す際にdouble splatを指定するよう修正しています。


Fix mocking test to mock kwargs

activestorage/test/models/attached/one_test.rbの修正です。

Hashをキーワード引数として渡す際にdouble splatを指定するよう修正しています。


Passing in a Hash instance as kwargs parameters requires the "double splat" prefix

各箇所でHashをキーワード引数として渡す際にdouble splatを指定するよう修正しています。


Keyword arguments is not a Hash

actioncable/test/channel/stream_test.rbの修正です。

キーワード引数を渡す際にHashとして渡していたのを、Hashではなくそのままキーワード引数として渡すよう修正しています。


Passing in a Hash instance as non-kwargs parameters has to be curly braced

Action Cableの修正です。

Hashを非キーワード引数として渡す際に{}で囲むよう修正しています。


else + ternary => elsif + else for clarity

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

else + 三項演算子の処理をelsif + elseにリファクタリングしています。


Registration#matches? takes keywords, and Registry#lookup is already called with keywords

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

Registry#lookupでキーワード引数を受け取るよう修正、及び、lookupから呼ぶ各メソッドにキーワード引数を渡すよう修正しています。

rails commit log流し読み(2019/09/06)

2019/09/06分のコミットです。

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

activestorage/CHANGELOG.md


Optimize Module#delegate to no longer be linear

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

Module#delegateメソッドでdelegate処理をする毎にmodule_evalを実行していたのを、極力module_evalの呼び出しを行わずにすむようリファクタリングしています。


Merge pull request #37139 from Shopify/define-url-helper-patch

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

UrlHelper.optimize_helper?でrouteのglob?より先にroute.path.requirements.empty?のチェックを行うよう修正しています。

(routingの内容によりますが)glob?は遅くなる事が多く、empty?チェックを先にする事で性能改善する事がある為。


Implement content disposition in direct upload

Active Storageの修正です。

クラウドサービスにdirect uploadを行う際に、ヘッダーにcontent dispositionを含むよう修正しています。


Fix comments to update mysql version in reference URL [ci skip]

activerecord/lib/arel/visitors/mysql.rbactiverecord/test/cases/arel/visitors/mysql_test.rbのdocの修正です。

MySQLのdocへのリンクのバージョンを5.0(https://dev.mysql.com/doc/refman/5.0/en)から8.0(https://dev.mysql.com/doc/refman/8.0/en)に更新しています。


Bump Capybara require version

railties/lib/rails/generators/rails/app/templates/Gemfile.ttの修正です。

rails newで生成されるGemfile内のCapybaraのバージョン指定を>= 3.26に修正しています。Stop setting a default Capybara app hostでCapybara 3.26以上がsysem testで必要になっている為。


Unify AR touch method signatures

Active Recordの修正です。

touchメソッドの引数定義を全てのクラス / モジュールで同じになるよう修正しています。


Revert "send with **options only when options is not empty"

RequestHelpersのメソッドを呼びだす際にoptionsが空でない場合にのみoptionsを指定するよう修正した、send with **options only when options is not emptyをRevertしています。

Ruby側で修正が入り空の場合でもエラーにならなくなった為。が、Ruby 2.5、2.6では動作しない(エラーになる)為、後ほどRevertされています。


AR save takes keyword arguments

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

saveメソッドでキーワード引数を受け取れるようメソッド定義を修正しています。


Passing in a Hash instance as kwargs parameters requires the "double splat" prefix

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

Hashをキーワード引数として渡す箇所にdouble splatの指定を追加しています。


Include kwargs definition in the generated method signatures and method calls

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

attribute methodsでキーワード引数を受け取れるよう修正しています。が、これによりテストがコケるようになってしまった為、後ほどRevertされています。


Keyword arguments is not a Hash

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

キーワード引数を渡す際にHashとして渡していたのを、Hashではなくそのままキーワード引数として渡すよう修正しています。


Revert "Revert "send with **options only when options is not empty""

Revert "send with **options only when options is not empty"を再度Revertしています。


Refactor define_url_helper to share the same instance between path and url

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

path helperとurl helperを定義するのにそれぞれ事なるUrlHelperインスタンスを使用していたのを、同じインスタンスを使い回すようリファクタリングしています。


Revert "Include kwargs definition in the generated method signatures and method calls"

attribute methodsでキーワード引数を受け取れるよう修正した、Include kwargs definition in the generated method signatures and method callsをRevertしています。

rails commit log流し読み(2019/09/05)

2019/09/05分のコミットです。

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

activesupport/CHANGELOG.md

actioncable/CHANGELOG.md

actionview/CHANGELOG.md


Merge pull request #37114 from iainbeeston/patch-1

activesupport/lib/active_support/notifications/instrumenter.rbの修正です。

Solarisで、Process::CLOCK_PROCESS_CPUTIME_IDを使用しないよう修正しています。SolarisではProcess::CLOCK_PROCESS_CPUTIME_IDはサポートされておらず、使用するとErrno::EINVALが発生してしまう為。


Passing in a Hash instance as kwargs parameters requires the "double splat" prefix

Action Viewの修正です。

Hashをキーワード引数として渡す際にdouble splatを指定するよう修正しています。


Passing in a Hash instance as non-kwargs parameters has to be curly braced now

actionview/test/template/url_helper_test.rbの修正です。

Hashを非キーワード引数として渡す際に{}で囲むよう修正しています。


Fix code block in the HTML version of the upgrade guide [ci skip]

rails guideのUpgrading Ruby on Railsの修正です。

All npm packages have been moved to the @rails scopeの項でコードブロックが正しく表示されるよう、直前に改行を追加しています。


Auto-correct rubocop offences

rubocopの設定に違反している箇所があったのをまとめて修正しています


Fix document formatting of Rails.group [ci skip]

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

Rails.groupメソッドのdocのフォーマットを修正しています。


Unify delete_multi_entries method signatute

activesupport/lib/active_support/cache/redis_cache_store.rbの修正です。

RedisCacheStore#delete_multi_entriesメソッドの引数を他のcache storeと合わせるよう修正しています。


These options are not defined as keyword arguments

activesupport/lib/active_support/cache.rbactivesupport/lib/active_support/cache/strategy/local_cache.rbの修正です。

キーワード引数ではないオプションからdouble splatの指定を削除しています。


Autoload the AS::SecureCompareRotator class:

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

autoloadの対象にActiveSupport::SecureCompareRotatorを追加しています。activesupport/allをrequireした際にロードされるようにする為。


Merge pull request #37040 from rails/reduce-info-level-logging

actioncable/lib/action_cable/channel/base.rbactionview/lib/action_view/log_subscriber.rbの修正です。

ACtion CableのsubscriptionのconfirmationとrejectionのログのログレベルをINFOからDEBUGに修正、及び、Action Viewのpartial renderとtemplateのrender開始のログのログレベルをINFOからDEBUGに修正しています。

Basecampで通常発生するログの量の削減を行っているらしく、その一環でINFOとして出す必要がないと思われるログについて、ログレベルの変更を行っています。

rails commit log流し読み(2019/09/04)

2019/09/04分のコミットです。

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


Do not set response "Vary" header if it has already been set

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

controllerでVary headerを指定していた場合に、_set_vary_headerメソッドで再度Vary headerを指定しないよう修正しています。


Fix typo [ci skip]

rails guideのAutoloading and Reloading Constants (Classic Mode)の修正です。

zeitwerkzeiwerkにタイポしていたのを修正しています。


Do not enforce no braces for hash argument

Hashを非キーワード引数として渡す際に{}で囲むようになった件と、Style/BracesAroundHashParameters copは内容が相反しているため、Style/BracesAroundHashParameters copは削除しています。

合わせて、rubocopの設定に違反している箇所があったのをまとめて修正しています


Add a test for select argument error with block

activerecord/test/cases/relations_test.rbの修正です。

select + blockを指定した場合にArgumentErrorになる事を確認するテストを追加しています。


No need to synchronize for just reading an ivar, at least in MRI

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

ConnectionPool::Queue#num_waitingメソッドでインスタンス変数を参照する際にsynchronize排他制御を行っていたのを、MRIでは排他制御を行わないよう修正しています。

MRIではインスタンス変数を参照するだけならsynchronizeは不要(GVLがある為)な為。JRubyについては本当に不要かどうかはわからないのでそのまま(synchronizeを使用する状態)になっています。


Ivar += in MRI is thread safe

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

with_new_connections_blockedメソッドでインスタンス変数に対して+=を行う際にsynchronizeを使用していたのを、MRIでは使用しないよう修正しています。MRIでは+=はスレッドセーフになっている為。


Merging options donesn't have to be synchronized

activesupport/lib/active_support/cache/memory_store.rbの修正です。

modify_valueメソッドでオプションのマージ処理も排他制御の対象になっていたのを、必要な箇所だけ排他制御行うよう修正しています。


No need to synchronize for just reading an ivar, at least in MRI

actionpack/lib/action_dispatch/http/response.rbの修正です。

Responseクラスでインスタンス変数を参照する際にsynchronize排他制御を行っていたのを、MRIでは排他制御を行わないよう修正しています。


Passing in a Hash instance as kwargs parameters requires the "double splat" prefix

Active Modelの修正です。

Hashをキーワード引数として渡す際にdouble splatを指定するよう修正しています。


The super_method at Type::Value takes kwargs

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

initializeでキーワード引数を受け取れれるよう引数指定を修正しています。


Include kwargs definition in the generated method signatures and method calls

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

attribute methodsを定義する際にキーワード引数を受け取れるよう修正しています。

が、この対応によりActive Recordのテストがコケるようになってしまった為後ほどRevertしています。


Revert "Include kwargs definition in the generated method signatures and method calls"

という訳で直前の対応をRevertしています。


These methods take keyword arguments

Active Recordの修正です。

Hashをキーワード引数として受け取れるようdouble splatの指定を追加しています。


Unify save method signatures to take keyword arguments

Active Recordの修正です。

引き続きHashをキーワード引数として受け取れるようdouble splatの指定を追加しています。


Safer example in Rails::Railtie documentation

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

Rails::Railtieのdoc内のRailsが定義されているかどうかをチェックするのに、defined?(Rails)を使用していたのをdefined?(Rails::Railtie)を使用するよう修正しています。

Railsアプリケーション以外でもRailsが定義されている事がある(e.g. 何らかのgemがRails namespaceを使用している場合)為、より正確にチェック出来るようにする為。


Document the new npm package names in the upgrade guide

rails guideのUpgrading Ruby on Railsの修正です。

npm packages名が6.0で変更になった旨説明している、All npm packages have been moved to the @rails scopeの項を追加しています。

rails commit log流し読み(2019/09/03)

2019/09/03分のコミットです。

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


Add title tag to mailer previews

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

mailer previewの詳細ページにtitleタグが無かったのを追加しています。


Merge pull request #37102 from y-yagi/fixes_37011

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

appディレクトリ直下に、ディレクトリではなくファイルがあった場合にRailsの初期化処理でエラーになってしまうバグがあったのを修正しています。


Fix href to replace http with https in the Yay! You’re on Rails! page

railties/lib/rails/templates/rails/welcome/index.html.erbの修正です。

Welcomeページで表示されるrubyonrails.orgへのリンクをhttpsに修正しています。


Prefer normal method call over method_missing

activesupport/lib/active_support/multibyte/chars.rbの修正です。

Chars#limitメソッドでtruncate_bytesを実行するのにmethod_missingに依存していたのを、必要なメソッドを直接呼ぶよう修正しています。


Passing in a Hash instance as non-kwargs parameters has to be braced in Ruby 3.0 syntax

activesupport/test/message_encryptor_test.rbactivesupport/test/message_verifier_test.rbの修正です。

Hashを非キーワード引数として渡す際に、{}で囲むよう修正しています。

Ruby 3.0に向けてのキーワード引数の挙動の整理がRuby 2.7で行われており、その対応の一環です。以降、同様にキーワード引数の対応が続きます。

参考: Feature #14183: "Real" keyword argument - Ruby master - Ruby Issue Tracking System


Passing in a Hash instance as kwargs parameters requires the "double splat" prefix

Hashをキーワード引数として渡す際にdouble splatを指定してkeyword splatが行われるよう修正しています。


I18n.translate takes kwargs options

activesupport/lib/active_support/number_helper/number_converter.rbの修正です。

translate_number_value_with_defaulttranslate_in_localeメソッドでキーワード引数にdouble splatを指定するよう修正しています。


:number is not a keyword argument

activesupport/lib/active_support/locale/en.rbの修正です。

ordinalsordinalizedの引数指定から:numberキーワード引数を削除しています。実際にはキーワード引数としては渡されてない(options引数として渡される)為。


subscribe block doesn't take keyword arguments

activesupport/test/deprecation_test.rbの修正です。

ActiveSupport::Notifications.subscribeを呼び出す際の引数をsingle splatに変更しています。subscribeはキーワード引数を受け取らない為。


Unify the API with Messages::Rotator::Verifier#verify that takes kwargs

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

Messages::Rotator::Verifier#verifyメソッドの引数指定にdouble splatを追加しています。


Introduce keyword arguments for some AS::Cache methods

ActiveSupport::Cacheの各メソッドの引数指定にdouble splatを追加しています。


Passing in a Hash instance as kwargs parameters requires the "double splat" prefix

actionpack/lib/action_dispatch/middleware/cookies.rbの修正です。

Hashをキーワード引数として渡す際にdouble splatを指定するよう修正しています。


Passing in a Hash instance as non-kwargs parameters has to be braced in Ruby 3.0 syntax

actionpack/test/dispatch/cookies_test.rbactionpack/test/dispatch/session/cookie_store_test.rbの修正です。

Hashを非キーワード引数として渡す際に、{}で囲むよう修正しています。


RequestEncoder.register_encoder takes keyworded arguments

actionpack/lib/action_dispatch/testing/integration.rbの修正です。

RequestEncoder.register_encoderでキーワード引数を受け取れるよう修正しています。


These RequestHelpers' methods take keyword arguments

actionpack/lib/action_dispatch/testing/integration.rbの修正です。

RequestHelpersのメソッドでキーワード引数を受け取れるよう引数指定を修正しています。


send with **options only when options is not empty

actionpack/lib/action_dispatch/testing/integration.rbの修正です。

RequestHelpersのメソッドを呼びだす際に、optionsが空でない場合にのみoptionsを指定するよう修正しています。ArgumentErrorが発生するのを避ける為。


Intern ActiveJob queue_name

activejob/lib/active_job/queue_name.rbの修正です。

queue_nameをfreezeするようにして不要なオブジェクトの生成を減らすよう修正しています。

rails commit log流し読み(2019/09/02)

2019/09/02分のコミットです。

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


Fix Active Job Sidekiq integration tests

activejob/test/support/integration/adapters/sidekiq.rbの修正です。

Sidekiqのloggerの指定方法がSidekiq 6.0変更になっており、https://github.com/mperham/sidekiq/wiki/Logging#api-changes に説明された内容に合わせてloggerの指定方法を修正しています。


Add tests for no or blank like arguments to query methods

activerecord/test/cases/relations_test.rbの修正です。

test_no_arguments_to_query_methods_raise_errorstest_blank_like_arguments_to_query_methods_dont_raise_errorsでテストするメソッドにordereager_load等のメソッドを追加しています。


Fix an error message to replace http with https in a reference URL

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

www.yaml.org へのリンクをhttpsに修正しています。