This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2021-04-24 08:01:43 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AccountSuggestions::Source
|
|
|
|
def key
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(_account, **kwargs)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove(_account, target_account_id)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def as_ordered_suggestions(scope, ordered_list)
|
|
|
|
return [] if ordered_list.empty?
|
|
|
|
|
2023-05-03 01:30:54 -07:00
|
|
|
map = scope.index_by { |account| to_ordered_list_key(account) }
|
2021-04-24 08:01:43 -07:00
|
|
|
|
2023-05-23 01:49:12 -07:00
|
|
|
ordered_list.filter_map { |ordered_list_key| map[ordered_list_key] }.map do |account|
|
2021-04-24 08:01:43 -07:00
|
|
|
AccountSuggestions::Suggestion.new(
|
|
|
|
account: account,
|
|
|
|
source: key
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_ordered_list_key(_account)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|