source.rb 704 B

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. class AccountSuggestions::Source
  3. def key
  4. raise NotImplementedError
  5. end
  6. def get(_account, **kwargs)
  7. raise NotImplementedError
  8. end
  9. def remove(_account, target_account_id)
  10. raise NotImplementedError
  11. end
  12. protected
  13. def as_ordered_suggestions(scope, ordered_list)
  14. return [] if ordered_list.empty?
  15. map = scope.index_by { |account| to_ordered_list_key(account) }
  16. ordered_list.filter_map { |ordered_list_key| map[ordered_list_key] }.map do |account|
  17. AccountSuggestions::Suggestion.new(
  18. account: account,
  19. source: key
  20. )
  21. end
  22. end
  23. def to_ordered_list_key(_account)
  24. raise NotImplementedError
  25. end
  26. end