Replace map + compact with filter_map

This commit is contained in:
Matheus Richard 2021-04-22 22:08:34 -03:00
parent 487ff1330c
commit c3d7794f16
11 changed files with 11 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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 = {})

View File

@ -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

View File

@ -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|

View File

@ -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

View File

@ -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)

View File

@ -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]}"