The code powering m.abunchtell.com https://m.abunchtell.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

45 行
879 B

  1. # frozen_string_literal: true
  2. class TagFilter
  3. attr_reader :params
  4. def initialize(params)
  5. @params = params
  6. end
  7. def results
  8. scope = Tag.unscoped
  9. params.each do |key, value|
  10. next if key.to_s == 'page'
  11. scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
  12. end
  13. scope.order(id: :desc)
  14. end
  15. private
  16. def scope_for(key, value)
  17. case key.to_s
  18. when 'directory'
  19. Tag.discoverable
  20. when 'reviewed'
  21. Tag.reviewed.order(reviewed_at: :desc)
  22. when 'unreviewed'
  23. Tag.unreviewed
  24. when 'pending_review'
  25. Tag.pending_review.order(requested_review_at: :desc)
  26. when 'popular'
  27. Tag.order('max_score DESC NULLS LAST')
  28. when 'active'
  29. Tag.order('last_status_at DESC NULLS LAST')
  30. when 'name'
  31. Tag.matches_name(value)
  32. else
  33. raise "Unknown filter: #{key}"
  34. end
  35. end
  36. end