about summary refs log tree commit diff
path: root/app/models/account_filter.rb
blob: a8d8c8837634ccc4d93fd7494206340c19247bc2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

class AccountFilter
  attr_reader :params

  def initialize(params)
    @params = params
  end

  def results
    scope = Account.alphabetic
    params.each do |key, value|
      scope = scope.merge scope_for(key, value)
    end
    scope
  end

  def scope_for(key, value)
    case key
    when /local/
      Account.local
    when /remote/
      Account.remote
    when /by_domain/
      Account.where(domain: value)
    when /silenced/
      Account.silenced
    when /recent/
      Account.recent
    when /suspended/
      Account.suspended
    else
      raise "Unknown filter: #{key}"
    end
  end
end