debian-mirror-gitlab/app/services/packages/nuget/sync_metadatum_service.rb
2020-08-09 17:44:08 +05:30

50 lines
1,002 B
Ruby

# frozen_string_literal: true
module Packages
module Nuget
class SyncMetadatumService
include Gitlab::Utils::StrongMemoize
def initialize(package, metadata)
@package = package
@metadata = metadata
end
def execute
if blank_metadata?
metadatum.destroy! if metadatum.persisted?
else
metadatum.update!(
license_url: license_url,
project_url: project_url,
icon_url: icon_url
)
end
end
private
def metadatum
strong_memoize(:metadatum) do
@package.nuget_metadatum || @package.build_nuget_metadatum
end
end
def blank_metadata?
project_url.blank? && license_url.blank? && icon_url.blank?
end
def project_url
@metadata[:project_url]
end
def license_url
@metadata[:license_url]
end
def icon_url
@metadata[:icon_url]
end
end
end
end