Optimize map { ... }.compact calls (#15513)
* Optimize map { ... }.compact using Enumerable#filter_map, supported since Ruby 2.7 * Add poyfill for Enumerable#filter_map
This commit is contained in:
parent
9395143126
commit
087ed84367
22 changed files with 52 additions and 26 deletions
|
@ -5,7 +5,7 @@ class ExistingUsernameValidator < ActiveModel::EachValidator
|
|||
return if value.blank?
|
||||
|
||||
if options[:multiple]
|
||||
missing_usernames = value.split(',').map { |username| username.strip.gsub(/\A@/, '') }.map { |username| username unless Account.find_local(username) }.compact
|
||||
missing_usernames = value.split(',').map { |username| username.strip.gsub(/\A@/, '') }.filter_map { |username| username unless Account.find_local(username) }
|
||||
record.errors.add(attribute, I18n.t('existing_username_validator.not_found_multiple', usernames: missing_usernames.join(', '))) if missing_usernames.any?
|
||||
else
|
||||
record.errors.add(attribute, I18n.t('existing_username_validator.not_found')) unless Account.find_local(value.strip.gsub(/\A@/, ''))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue