debian-mirror-gitlab/app/finders/packages/npm/package_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.3 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Packages
module Npm
class PackageFinder
delegate :find_by_version, to: :execute
2021-04-17 20:07:23 +05:30
delegate :last, to: :execute
2020-07-28 23:09:34 +05:30
2021-11-11 11:23:49 +05:30
# /!\ CAUTION: don't use last_of_each_version: false with find_by_version. Ordering is not
# guaranteed!
def initialize(package_name, project: nil, namespace: nil, last_of_each_version: true)
2020-07-28 23:09:34 +05:30
@package_name = package_name
2021-04-17 20:07:23 +05:30
@project = project
@namespace = namespace
2021-11-11 11:23:49 +05:30
@last_of_each_version = last_of_each_version
2020-07-28 23:09:34 +05:30
end
def execute
2021-11-11 11:23:49 +05:30
result = base.npm
.with_name(@package_name)
.installable
return result unless @last_of_each_version
2023-06-20 00:43:36 +05:30
if Feature.enabled?(:npm_allow_packages_in_multiple_projects)
Packages::Package.id_in(result.last_of_each_version_ids)
else
result.last_of_each_version
end
2020-07-28 23:09:34 +05:30
end
private
2021-04-17 20:07:23 +05:30
def base
if @project
packages_for_project
elsif @namespace
packages_for_namespace
else
::Packages::Package.none
end
end
def packages_for_project
@project.packages
end
def packages_for_namespace
::Packages::Package.for_projects(@namespace.all_projects)
2020-07-28 23:09:34 +05:30
end
end
end
end