You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
693 B

  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(&method(:to_ordered_list_key))
  16. ordered_list.map { |ordered_list_key| map[ordered_list_key] }.compact.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