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-04-17 20:07:23 +05:30
|
|
|
def initialize(package_name, project: nil, namespace: nil)
|
2020-07-28 23:09:34 +05:30
|
|
|
@package_name = package_name
|
2021-04-17 20:07:23 +05:30
|
|
|
@project = project
|
|
|
|
@namespace = namespace
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2021-04-17 20:07:23 +05:30
|
|
|
base.npm
|
|
|
|
.with_name(@package_name)
|
2021-06-08 01:23:25 +05:30
|
|
|
.installable
|
2021-04-17 20:07:23 +05:30
|
|
|
.last_of_each_version
|
|
|
|
.preload_files
|
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
|