0
0
Fork 0

Fix Style/SlicingWithRange cop (#25923)

This commit is contained in:
Matt Jankowski 2023-07-12 04:03:06 -04:00 committed by GitHub
parent 658742b3cd
commit b8b2470cf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 13 additions and 28 deletions

View file

@ -25,7 +25,7 @@ class AccountAlias < ApplicationRecord
def acct=(val)
val = val.to_s.strip
super(val.start_with?('@') ? val[1..-1] : val)
super(val.start_with?('@') ? val[1..] : val)
end
def pretty_acct

View file

@ -69,7 +69,7 @@ class DomainBlock < ApplicationRecord
uri = Addressable::URI.new.tap { |u| u.host = domain.strip.delete('/') }
segments = uri.normalized_host.split('.')
variants = segments.map.with_index { |_, i| segments[i..-1].join('.') }
variants = segments.map.with_index { |_, i| segments[i..].join('.') }
where(domain: variants).order(Arel.sql('char_length(domain) desc')).first
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError

View file

@ -64,7 +64,7 @@ class EmailDomainBlock < ApplicationRecord
segments = uri.normalized_host.split('.')
segments.map.with_index { |_, i| segments[i..-1].join('.') }
segments.map.with_index { |_, i| segments[i..].join('.') }
end
end

View file

@ -54,6 +54,6 @@ class PreviewCardProvider < ApplicationRecord
def self.matching_domain(domain)
segments = domain.split('.')
where(domain: segments.map.with_index { |_, i| segments[i..-1].join('.') }).order(Arel.sql('char_length(domain) desc')).first
where(domain: segments.map.with_index { |_, i| segments[i..].join('.') }).order(Arel.sql('char_length(domain) desc')).first
end
end