From c3d7794f1687305d34210dd776c6df2cbaa71342 Mon Sep 17 00:00:00 2001 From: Matheus Richard Date: Thu, 22 Apr 2021 22:08:34 -0300 Subject: [PATCH] Replace map + compact with filter_map --- actioncable/lib/action_cable/channel/test_case.rb | 2 +- actioncable/lib/action_cable/connection/identification.rb | 2 +- actionpack/lib/abstract_controller/caching.rb | 2 +- actionpack/lib/action_controller/metal/rendering.rb | 2 +- actionpack/lib/action_controller/metal/strong_parameters.rb | 2 +- actiontext/lib/action_text/attachment.rb | 2 +- actionview/test/template/digestor_test.rb | 2 +- activerecord/Rakefile | 2 +- activerecord/lib/active_record/nested_attributes.rb | 2 +- activerecord/lib/arel/select_manager.rb | 2 +- railties/lib/rails/commands/dbconsole/dbconsole_command.rb | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/actioncable/lib/action_cable/channel/test_case.rb b/actioncable/lib/action_cable/channel/test_case.rb index ba8971ee63..8923cdaff7 100644 --- a/actioncable/lib/action_cable/channel/test_case.rb +++ b/actioncable/lib/action_cable/channel/test_case.rb @@ -246,7 +246,7 @@ module ActionCable # Returns messages transmitted into channel def transmissions # Return only directly sent message (via #transmit) - connection.transmissions.map { |data| data["message"] }.compact + connection.transmissions.filter_map { |data| data["message"] } end # Enhance TestHelper assertions to handle non-String diff --git a/actioncable/lib/action_cable/connection/identification.rb b/actioncable/lib/action_cable/connection/identification.rb index cc544685dd..519f64ba9c 100644 --- a/actioncable/lib/action_cable/connection/identification.rb +++ b/actioncable/lib/action_cable/connection/identification.rb @@ -26,7 +26,7 @@ module ActionCable # Return a single connection identifier that combines the value of all the registered identifiers into a single gid. def connection_identifier unless defined? @connection_identifier - @connection_identifier = connection_gid identifiers.map { |id| instance_variable_get("@#{id}") }.compact + @connection_identifier = connection_gid identifiers.filter_map { |id| instance_variable_get("@#{id}") } end @connection_identifier diff --git a/actionpack/lib/abstract_controller/caching.rb b/actionpack/lib/abstract_controller/caching.rb index 5e9cb4d2f9..3b6f9b1cef 100644 --- a/actionpack/lib/abstract_controller/caching.rb +++ b/actionpack/lib/abstract_controller/caching.rb @@ -50,7 +50,7 @@ module AbstractController end def view_cache_dependencies - self.class._view_cache_dependencies.map { |dep| instance_exec(&dep) }.compact + self.class._view_cache_dependencies.filter_map { |dep| instance_exec(&dep) } end private diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index f0029f30d9..5d65a11b48 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -26,7 +26,7 @@ module ActionController # Before processing, set the request formats in current controller formats. def process_action(*) #:nodoc: - self.formats = request.formats.map(&:ref).compact + self.formats = request.formats.filter_map(&:ref) super end diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index b6058f9402..c14220bf6e 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -955,7 +955,7 @@ module ActionController def each_element(object, &block) case object when Array - object.grep(Parameters).map { |el| yield el }.compact + object.grep(Parameters).filter_map { |el| yield el } when Parameters if object.nested_attributes? object.each_nested_attribute(&block) diff --git a/actiontext/lib/action_text/attachment.rb b/actiontext/lib/action_text/attachment.rb index b91d6133bc..2e07a42171 100644 --- a/actiontext/lib/action_text/attachment.rb +++ b/actiontext/lib/action_text/attachment.rb @@ -20,7 +20,7 @@ module ActionText end def from_attachables(attachables) - Array(attachables).map { |attachable| from_attachable(attachable) }.compact + Array(attachables).filter_map { |attachable| from_attachable(attachable) } end def from_attachable(attachable, attributes = {}) diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb index 4515afdfff..8eea69eb47 100644 --- a/actionview/test/template/digestor_test.rb +++ b/actionview/test/template/digestor_test.rb @@ -363,7 +363,7 @@ class TemplateDigestorTest < ActionView::TestCase def tree_template_formats(template_name) tree = ActionView::Digestor.tree(template_name, finder) - tree.flatten.map(&:template).compact.map(&:format) + tree.flatten.filter_map { |node| node.template&.format } end def disable_resolver_caching diff --git a/activerecord/Rakefile b/activerecord/Rakefile index 40c1eb9b3f..ed101bee35 100644 --- a/activerecord/Rakefile +++ b/activerecord/Rakefile @@ -119,7 +119,7 @@ end n = ENV["BUILDKITE_PARALLEL_JOB"].to_i m = ENV["BUILDKITE_PARALLEL_JOB_COUNT"].to_i - test_files = test_files.each_slice(m).map { |slice| slice[n] }.compact + test_files = test_files.each_slice(m).filter_map { |slice| slice[n] } end test_files.each do |file| diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index 262c03ea92..fb311ead0e 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -486,7 +486,7 @@ module ActiveRecord existing_records = if association.loaded? association.target else - attribute_ids = attributes_collection.map { |a| a["id"] || a[:id] }.compact + attribute_ids = attributes_collection.filter_map { |a| a["id"] || a[:id] } attribute_ids.empty? ? [] : association.scope.where(association.klass.primary_key => attribute_ids) end diff --git a/activerecord/lib/arel/select_manager.rb b/activerecord/lib/arel/select_manager.rb index e02c602b83..dada3324ea 100644 --- a/activerecord/lib/arel/select_manager.rb +++ b/activerecord/lib/arel/select_manager.rb @@ -96,7 +96,7 @@ module Arel # :nodoc: all end def froms - @ast.cores.map { |x| x.from }.compact + @ast.cores.filter_map { |x| x.from } end def join(relation, klass = Nodes::InnerJoin) diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index ccb475e19c..53a6c68fcc 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -31,7 +31,7 @@ module Rails sslcapath: "--ssl-capath", sslcipher: "--ssl-cipher", sslkey: "--ssl-key" - }.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact + }.filter_map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] } if config[:password] && @options[:include_password] args << "--password=#{config[:password]}"