logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

report_filter.rb (560B)


  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 :resolved
  17. Report.resolved
  18. when :account_id
  19. Report.where(account_id: value)
  20. when :target_account_id
  21. Report.where(target_account_id: value)
  22. else
  23. raise "Unknown filter: #{key}"
  24. end
  25. end
  26. end