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
654 B

  1. # frozen_string_literal: true
  2. class ReportFilter
  3. attr_reader :params
  4. def initialize(params)
  5. @params = params
  6. end
  7. def results
  8. scope = Report.unresolved
  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.to_sym
  16. when :by_target_domain
  17. Report.where(target_account: Account.where(domain: value))
  18. when :resolved
  19. Report.resolved
  20. when :account_id
  21. Report.where(account_id: value)
  22. when :target_account_id
  23. Report.where(target_account_id: value)
  24. else
  25. raise "Unknown filter: #{key}"
  26. end
  27. end
  28. end