diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-03-01 19:59:03 +0300 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-03-06 22:18:26 +0300 |
commit | 005749a616c19b90d6ec0415df9ae5e35151e33c (patch) | |
tree | f1618dbe99a4ed60980dc94f831864f9e701c589 /app/finders | |
parent | 2b474dc2b226460782413e634792cf83e791173b (diff) |
apply codestyle and implementation changes to the respective feature code
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/personal_access_tokens_finder.rb | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/app/finders/personal_access_tokens_finder.rb b/app/finders/personal_access_tokens_finder.rb index 7b9a2f6c0bb..760166b453f 100644 --- a/app/finders/personal_access_tokens_finder.rb +++ b/app/finders/personal_access_tokens_finder.rb @@ -1,36 +1,34 @@ class PersonalAccessTokensFinder attr_accessor :params + delegate :build, :find, :find_by, to: :execute + def initialize(params = {}) @params = params end - def execute(token: nil, id: nil) - tokens = by_impersonation - - return tokens.find_by_token(token) if token - return tokens.find_by_id(id) if id - - tokens = by_state(tokens) - tokens.order(@params[:order]) if @params[:order] - - tokens + def execute + tokens = PersonalAccessToken.all + tokens = by_user(tokens) + tokens = by_impersonation(tokens) + by_state(tokens) end private - def personal_access_tokens - @params[:user] ? @params[:user].personal_access_tokens : PersonalAccessToken.all + def by_user(tokens) + return tokens unless @params[:user] + tokens.where(user: @params[:user]) end - def by_impersonation + def by_impersonation(tokens) case @params[:impersonation] when true - personal_access_tokens.with_impersonation + tokens.with_impersonation when false - personal_access_tokens.without_impersonation + tokens.without_impersonation else - personal_access_tokens + tokens end end |