Class: MergeRequests::ByApprovalsFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/merge_requests/by_approvals_finder.rb

Overview

Used to filter MergeRequest collections by approvers

Constant Summary collapse

MAX_FILTER_ELEMENTS =

We apply a limitation to the amount of elements that can be part of the filter condition

5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(usernames, ids) ⇒ ByApprovalsFinder

Initialize the finder

Parameters:

  • usernames (Array<String>)
  • ids (Array<Integers>)


15
16
17
18
19
20
# File 'app/finders/merge_requests/by_approvals_finder.rb', line 15

def initialize(usernames, ids)
  # rubocop:disable CodeReuse/ActiveRecord
  @usernames = Array(usernames).map(&:to_s).uniq.take(MAX_FILTER_ELEMENTS)
  @ids = Array(ids).uniq.take(MAX_FILTER_ELEMENTS)
  # rubocop:enable CodeReuse/ActiveRecord
end

Instance Attribute Details

#idsObject (readonly)

Returns the value of attribute ids.



6
7
8
# File 'app/finders/merge_requests/by_approvals_finder.rb', line 6

def ids
  @ids
end

#usernamesObject (readonly)

Returns the value of attribute usernames.



6
7
8
# File 'app/finders/merge_requests/by_approvals_finder.rb', line 6

def usernames
  @usernames
end

Instance Method Details

#execute(items) ⇒ Object

Filter MergeRequest collections by approvers

Parameters:

  • items (ActiveRecord::Relation)

    the activerecord relation



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/finders/merge_requests/by_approvals_finder.rb', line 25

def execute(items)
  if by_no_approvals?
    without_approvals(items)
  elsif by_any_approvals?
    with_any_approvals(items)
  elsif ids.present?
    find_approved_by_ids(items)
  elsif usernames.present?
    find_approved_by_names(items)
  else
    items
  end
end