diff options
author | Eugen <eugen@zeonfederated.com> | 2017-04-13 13:26:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-13 13:26:16 +0200 |
commit | 1a12fd14d438380e24421e9c8a8894cc705aba51 (patch) | |
tree | b276d81e18839706eaebe1db5870edc0b8628064 /app/models/account_filter.rb | |
parent | a18fd491b9ad9b2e1677d0e0355712a08967fe14 (diff) | |
parent | 282bb55c3cae07229d4c9a2fe58c1c2a136c57b9 (diff) |
Merge branch 'master' into master
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 |