Class: Packages::Rubygems::DependencyResolverService

Inherits:
BaseService
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/packages/rubygems/dependency_resolver_service.rb

Constant Summary collapse

DEFAULT_PLATFORM =
'ruby'

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#executeObject


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/packages/rubygems/dependency_resolver_service.rb', line 10

def execute
  return ServiceResponse.error(message: "forbidden", http_status: :forbidden) unless Ability.allowed?(current_user, :read_package, project)
  return ServiceResponse.error(message: "#{gem_name} not found", http_status: :not_found) if packages.empty?

  payload = packages.map do |package|
    dependencies = package.dependency_links.map do |link|
      [link.dependency.name, link.dependency.version_pattern]
    end

    {
      name: gem_name,
      number: package.version,
      platform: DEFAULT_PLATFORM,
      dependencies: dependencies
    }
  end

  ServiceResponse.success(payload: payload)
end