Class: MergeRequests::ByApprovalsFinder
- Inherits:
-
Object
- Object
- MergeRequests::ByApprovalsFinder
- 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
-
#ids ⇒ Object
readonly
Returns the value of attribute ids.
-
#usernames ⇒ Object
readonly
Returns the value of attribute usernames.
Instance Method Summary collapse
-
#execute(items) ⇒ Object
Filter MergeRequest collections by approvers.
-
#initialize(usernames, ids) ⇒ ByApprovalsFinder
constructor
Initialize the finder.
Constructor Details
#initialize(usernames, ids) ⇒ ByApprovalsFinder
Initialize the finder
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
#ids ⇒ Object (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 |
#usernames ⇒ Object (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
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 |