where i deviate from standard mastodon assets
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.

invite_filter.rb 560B

12345678910111213141516171819202122232425262728293031323334353637
  1. # frozen_string_literal: true
  2. class InviteFilter
  3. KEYS = %i(
  4. available
  5. expired
  6. ).freeze
  7. attr_reader :params
  8. def initialize(params)
  9. @params = params
  10. end
  11. def results
  12. scope = Invite.order(created_at: :desc)
  13. params.each do |key, value|
  14. scope.merge!(scope_for(key, value)) if value.present?
  15. end
  16. scope
  17. end
  18. private
  19. def scope_for(key, _value)
  20. case key.to_s
  21. when 'available'
  22. Invite.available
  23. when 'expired'
  24. Invite.expired
  25. else
  26. raise "Unknown filter: #{key}"
  27. end
  28. end
  29. end