0
0
Fork 0

Fix Lint/DuplicateBranch cop (#24766)

This commit is contained in:
Matt Jankowski 2023-05-02 06:57:11 -04:00 committed by GitHub
parent f50105779b
commit 88d33f361f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 31 deletions

View file

@ -8,19 +8,49 @@ class PermalinkRedirector
end
def redirect_path
if path_segments[0].present? && path_segments[0].start_with?('@') && path_segments[1] =~ /\d/
find_status_url_by_id(path_segments[1])
elsif path_segments[0].present? && path_segments[0].start_with?('@')
find_account_url_by_name(path_segments[0])
elsif path_segments[0] == 'statuses' && path_segments[1] =~ /\d/
find_status_url_by_id(path_segments[1])
elsif path_segments[0] == 'accounts' && path_segments[1] =~ /\d/
find_account_url_by_id(path_segments[1])
if at_username_status_request? || statuses_status_request?
find_status_url_by_id(second_segment)
elsif at_username_request?
find_account_url_by_name(first_segment)
elsif accounts_request? && record_integer_id_request?
find_account_url_by_id(second_segment)
end
end
private
def at_username_status_request?
at_username_request? && record_integer_id_request?
end
def statuses_status_request?
statuses_request? && record_integer_id_request?
end
def at_username_request?
first_segment.present? && first_segment.start_with?('@')
end
def statuses_request?
first_segment == 'statuses'
end
def accounts_request?
first_segment == 'accounts'
end
def record_integer_id_request?
second_segment =~ /\d/
end
def first_segment
path_segments.first
end
def second_segment
path_segments.second
end
def path_segments
@path_segments ||= @path.gsub(/\A\//, '').split('/')
end