Pass project IDs relation to ProjectsFinder instead of using a block

This commit is contained in:
Ahmad Sherif 2016-08-12 15:52:58 +02:00
parent d13c36f72d
commit 76db0dc115
2 changed files with 3 additions and 5 deletions

View File

@ -1,7 +1,7 @@
class ProjectsFinder < UnionFinder class ProjectsFinder < UnionFinder
def execute(current_user = nil, options = {}, &block) def execute(current_user = nil, project_ids_relation = nil)
segments = all_projects(current_user) segments = all_projects(current_user)
segments.map!(&block) if block segments.map! { |s| s.where(id: project_ids_relation) } if project_ids_relation
find_union(segments, Project) find_union(segments, Project)
end end

View File

@ -95,9 +95,7 @@ class TodosFinder
def projects(items) def projects(items)
item_project_ids = items.reorder(nil).select(:project_id) item_project_ids = items.reorder(nil).select(:project_id)
ProjectsFinder.new.execute(current_user) do |relation| ProjectsFinder.new.execute(current_user, item_project_ids)
relation.where(id: item_project_ids)
end
end end
def type? def type?