Class: PendingTodosFinder
- Inherits:
-
Object
- Object
- PendingTodosFinder
- Defined in:
- app/finders/pending_todos_finder.rb
Overview
Finder for retrieving the pending todos of a user, optionally filtered using various fields.
While this finder is a bit more verbose compared to use `where(params.slice(…))`, it allows us to decouple the input parameters from the actual column names. For example, if we ever decide to use separate columns for target types (e.g. `issue_id`, `merge_request_id`, etc), we no longer need to change everything that uses this finder. Instead, we just change the various `by_*` methods in this finder, without having to touch everything that uses it.
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#users ⇒ Object
readonly
Returns the value of attribute users.
Instance Method Summary collapse
- #by_action(todos) ⇒ Object
- #by_commit_id(todos) ⇒ Object
- #by_discussion(todos) ⇒ Object
- #by_project(todos) ⇒ Object
- #by_target_id(todos) ⇒ Object
- #by_target_type(todos) ⇒ Object
- #execute ⇒ Object
-
#initialize(users, params = {}) ⇒ PendingTodosFinder
constructor
users - The list of users to retrieve the todos for.
Constructor Details
#initialize(users, params = {}) ⇒ PendingTodosFinder
users - The list of users to retrieve the todos for. params - A Hash containing columns and values to use for filtering todos.
18 19 20 21 |
# File 'app/finders/pending_todos_finder.rb', line 18 def initialize(users, params = {}) @users = users @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
14 15 16 |
# File 'app/finders/pending_todos_finder.rb', line 14 def params @params end |
#users ⇒ Object (readonly)
Returns the value of attribute users.
14 15 16 |
# File 'app/finders/pending_todos_finder.rb', line 14 def users @users end |
Instance Method Details
#by_action(todos) ⇒ Object
74 75 76 77 78 |
# File 'app/finders/pending_todos_finder.rb', line 74 def by_action(todos) return todos if params[:action].blank? todos.for_action(params[:action]) end |
#by_commit_id(todos) ⇒ Object
58 59 60 61 62 63 64 |
# File 'app/finders/pending_todos_finder.rb', line 58 def by_commit_id(todos) if (id = params[:commit_id]) todos.for_commit(id) else todos end end |
#by_discussion(todos) ⇒ Object
66 67 68 69 70 71 72 |
# File 'app/finders/pending_todos_finder.rb', line 66 def by_discussion(todos) if (discussion = params[:discussion]) todos.for_note(discussion.notes) else todos end end |
#by_project(todos) ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/finders/pending_todos_finder.rb', line 34 def by_project(todos) if (id = params[:project_id]) todos.for_project(id) else todos end end |
#by_target_id(todos) ⇒ Object
42 43 44 45 46 47 48 |
# File 'app/finders/pending_todos_finder.rb', line 42 def by_target_id(todos) if (id = params[:target_id]) todos.for_target(id) else todos end end |
#by_target_type(todos) ⇒ Object
50 51 52 53 54 55 56 |
# File 'app/finders/pending_todos_finder.rb', line 50 def by_target_type(todos) if (type = params[:target_type]) todos.for_type(type) else todos end end |
#execute ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'app/finders/pending_todos_finder.rb', line 23 def execute todos = Todo.for_user(users) todos = todos.pending todos = by_project(todos) todos = by_target_id(todos) todos = by_target_type(todos) todos = by_discussion(todos) todos = by_commit_id(todos) by_action(todos) end |