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.

28 lines
485 B

  1. # frozen_string_literal: true
  2. class InstanceFilter
  3. attr_reader :params
  4. def initialize(params)
  5. @params = params
  6. end
  7. def results
  8. scope = Account.remote.by_domain_accounts
  9. params.each do |key, value|
  10. scope.merge!(scope_for(key, value)) if value.present?
  11. end
  12. scope
  13. end
  14. private
  15. def scope_for(key, value)
  16. case key.to_s
  17. when 'domain_name'
  18. Account.matches_domain(value)
  19. else
  20. raise "Unknown filter: #{key}"
  21. end
  22. end
  23. end