logo

mastofe

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

invite_filter.rb (509B)


  1. # frozen_string_literal: true
  2. class InviteFilter
  3. attr_reader :params
  4. def initialize(params)
  5. @params = params
  6. end
  7. def results
  8. scope = Invite.order(created_at: :desc)
  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 'available'
  18. Invite.available
  19. when 'expired'
  20. Invite.expired
  21. else
  22. raise "Unknown filter: #{key}"
  23. end
  24. end
  25. end