diff options
Diffstat (limited to 'app/models/account_filter.rb')
-rw-r--r-- | app/models/account_filter.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb new file mode 100644 index 000000000..a8d8c8837 --- /dev/null +++ b/app/models/account_filter.rb @@ -0,0 +1,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 |