summaryrefslogtreecommitdiff
path: root/app/contexts/filter_context.rb
blob: e7f80e1a4e4fbeeeb023d748dddd1ac63b10ac60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class FilterContext
  attr_accessor :items, :params

  def initialize(items, params)
    @items = items
    @params = params
  end

  def execute
    apply_filter(items)
  end

  def apply_filter items
    if params[:project_id]
      items = items.by_project(params[:project_id])
    end

    if params[:search].present?
      items = items.search(params[:search])
    end

    case params[:status]
    when 'closed'
      items.closed
    when 'all'
      items
    else
      items.opened
    end
  end
end