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.

36 lines
641 B

  1. # frozen_string_literal: true
  2. class AccountFilter
  3. attr_reader :params
  4. def initialize(params)
  5. @params = params
  6. end
  7. def results
  8. scope = Account.alphabetic
  9. params.each do |key, value|
  10. scope = scope.merge scope_for(key, value)
  11. end
  12. scope
  13. end
  14. def scope_for(key, value)
  15. case key
  16. when /local/
  17. Account.local
  18. when /remote/
  19. Account.remote
  20. when /by_domain/
  21. Account.where(domain: value)
  22. when /silenced/
  23. Account.silenced
  24. when /recent/
  25. Account.recent
  26. when /suspended/
  27. Account.suspended
  28. else
  29. raise "Unknown filter: #{key}"
  30. end
  31. end
  32. end