blob: c533cb266a2a5b42a02190406dc316008040380f (
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
32
33
34
35
36
37
38
39
40
41
|
# frozen_string_literal: true
module Packages
class PackagesFinder
attr_reader :params, :project
def initialize(project, params = {})
@project = project
@params = params
params[:order_by] ||= 'created_at'
params[:sort] ||= 'asc'
end
def execute
packages = project.packages.processed.has_version
packages = filter_by_package_type(packages)
packages = filter_by_package_name(packages)
packages = order_packages(packages)
packages
end
private
def filter_by_package_type(packages)
return packages unless params[:package_type]
packages.with_package_type(params[:package_type])
end
def filter_by_package_name(packages)
return packages unless params[:package_name]
packages.search_by_name(params[:package_name])
end
def order_packages(packages)
packages.sort_by_attribute("#{params[:order_by]}_#{params[:sort]}")
end
end
end
|