rails--rails/activestorage/test/service
Koichi ITO 819871cc4e Enable `Style/MapToHash` cop
Ruby 2.6 added block argument processing to `Enumerable#to_h`.
https://bugs.ruby-lang.org/issues/15143

Rails 7 requires Ruby 2.7.0 or higher, so the new feature can use it.
`Style/MapToHash` cop will detect it. And this cop in the `Style` department,
but this seems to improve performance as follows:

```ruby
# map_to_hash.rb
require 'benchmark/ips'

ARRAY = (1..100).to_a
HASH = {foo: 1, bar: 2}

Benchmark.ips do |x|
  x.report('array.map.to_h') { ARRAY.map { |v| [v, v * 2] }.to_h }
  x.report('array.to_h')     { ARRAY.to_h { |v| [v, v * 2] } }

  x.compare!
end

Benchmark.ips do |x|
  x.report('hash.map.to_h') { HASH.map { |k, v| [k.to_s, v * 2] }.to_h }
  x.report('hash.to_h')     { HASH.to_h { |k, v| [k.to_s, v * 2] } }

  x.compare!
end
```

```console
% ruby map_to_hash.rb
Warming up --------------------------------------
      array.map.to_h     9.063k i/100ms
          array.to_h     9.609k i/100ms
Calculating -------------------------------------
      array.map.to_h     89.063k (± 3.9%) i/s -    453.150k in  5.096572s
          array.to_h     96.449k (± 1.7%) i/s -    490.059k in  5.082529s

Comparison:
          array.to_h:    96448.7 i/s
      array.map.to_h:    89063.4 i/s - 1.08x  (± 0.00) slower

Warming up --------------------------------------
       hash.map.to_h   106.284k i/100ms
           hash.to_h   149.354k i/100ms
Calculating -------------------------------------
       hash.map.to_h      1.102M (± 2.2%) i/s -      5.527M in   5.019657s
           hash.to_h      1.490M (± 0.9%) i/s -      7.468M in   5.013264s

Comparison:
           hash.to_h:  1489707.0 i/s
       hash.map.to_h:  1101561.5 i/s - 1.35x  (± 0.00) slower
```

`Style/MapToHash` cop ... https://docs.rubocop.org/rubocop/1.25/cops_style.html#stylemaptohash
2022-02-26 04:31:03 +09:00
..
azure_storage_public_service_test.rb Always use OpenSSL constants for Digest operations 2021-06-30 13:57:54 +02:00
azure_storage_service_test.rb Introduce custom metadata 2021-11-23 17:35:33 -05:00
configurations.example.yml Optionally use IAM for URL signing instead of :credentials 2021-07-13 15:44:08 -04:00
configurations.yml.enc Update ASt test services config 2018-03-12 19:00:54 -04:00
configurator_test.rb Improve ActiveStorage service adapter error handling 2018-08-06 18:17:49 -07:00
disk_public_service_test.rb Remove query params in DiskService 2019-12-06 16:52:30 -05:00
disk_service_test.rb Slient the warning for ActiveStorage::Current.host logged in test cases 2021-08-10 21:58:01 +05:30
gcs_public_service_test.rb Always use OpenSSL constants for Digest operations 2021-06-30 13:57:54 +02:00
gcs_service_test.rb Introduce custom metadata 2021-11-23 17:35:33 -05:00
mirror_service_test.rb Enable `Style/MapToHash` cop 2022-02-26 04:31:03 +09:00
s3_public_service_test.rb Always use OpenSSL constants for Digest operations 2021-06-30 13:57:54 +02:00
s3_service_test.rb Introduce custom metadata 2021-11-23 17:35:33 -05:00
shared_service_tests.rb Pass an array through our stack, don't bother converting back & forth 2021-12-04 02:25:42 +01:00