forked from asonix/mastodon
* Fix unused role routes being generated * Remove unused JavaScript code * Refactor filters code to be DRYer * Fix `.count == 0` comparisons to `.empty?` in views * Fix filters in views
37 lines
560 B
Ruby
37 lines
560 B
Ruby
# frozen_string_literal: true
|
|
|
|
class InviteFilter
|
|
KEYS = %i(
|
|
available
|
|
expired
|
|
).freeze
|
|
|
|
attr_reader :params
|
|
|
|
def initialize(params)
|
|
@params = params
|
|
end
|
|
|
|
def results
|
|
scope = Invite.order(created_at: :desc)
|
|
|
|
params.each do |key, value|
|
|
scope.merge!(scope_for(key, value)) if value.present?
|
|
end
|
|
|
|
scope
|
|
end
|
|
|
|
private
|
|
|
|
def scope_for(key, _value)
|
|
case key.to_s
|
|
when 'available'
|
|
Invite.available
|
|
when 'expired'
|
|
Invite.expired
|
|
else
|
|
raise "Unknown filter: #{key}"
|
|
end
|
|
end
|
|
end
|