From 7315b3e82965113f208b9471b2260a13cf820887 Mon Sep 17 00:00:00 2001 From: Zeke Gabrielse Date: Tue, 22 Oct 2024 16:11:51 -0500 Subject: [PATCH] refactor gemspec parsing --- .../rubygems/compact_index_controller.rb | 5 ++- app/models/release_specification.rb | 31 ++----------------- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/app/controllers/api/v1/release_engines/rubygems/compact_index_controller.rb b/app/controllers/api/v1/release_engines/rubygems/compact_index_controller.rb index 335390cbf4..b24690dbbc 100644 --- a/app/controllers/api/v1/release_engines/rubygems/compact_index_controller.rb +++ b/app/controllers/api/v1/release_engines/rubygems/compact_index_controller.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'rubygems/specification' require 'compact_index' module Api::V1::ReleaseEngines @@ -22,7 +21,7 @@ def versions .map do |package| versions = package.published_releases.flat_map do |release| release.uploaded_artifacts.map do |artifact| - gemspec = Gem::Specification.from_yaml(artifact.specification.content) + gemspec = artifact.specification.as_gemspec dependencies = gemspec.dependencies.map do |dependency| CompactIndex::Dependency.new(dependency.name.to_s, dependency.requirement.to_s) end @@ -57,7 +56,7 @@ def info .distinct .flat_map do |release| release.uploaded_artifacts.map do |artifact| - gemspec = Gem::Specification.from_yaml(artifact.specification.content) + gemspec = artifact.specification.as_gemspec dependencies = gemspec.dependencies.map do |dependency| CompactIndex::Dependency.new(dependency.name.to_s, dependency.requirement.to_s) end diff --git a/app/models/release_specification.rb b/app/models/release_specification.rb index aa8789db22..653dfdb021 100644 --- a/app/models/release_specification.rb +++ b/app/models/release_specification.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'rubygems/specification' + class ReleaseSpecification < ApplicationRecord MIN_CONTENT_LENGTH = 5.bytes # to avoid processing empty or invalid specs MAX_CONTENT_LENGTH = 5.megabytes # to avoid downloading large specs @@ -45,32 +47,5 @@ class ReleaseSpecification < ApplicationRecord end end - # scope :waiting, -> { joins(:artifact).where(release_artifacts: { status: 'WAITING' }) } - # scope :processing, -> { joins(:artifact).where(release_artifacts: { status: 'PROCESSING' }) } - # scope :uploaded, -> { joins(:artifact).where(release_artifacts: { status: 'UPLOADED' }) } - # scope :failed, -> { joins(:artifact).where(release_artifacts: { status: 'FAILED' }) } - - # scope :draft, -> { joins(:release).where(releases: { status: 'DRAFT' }) } - # scope :published, -> { joins(:release).where(releases: { status: 'PUBLISHED' }) } - # scope :yanked, -> { joins(:release).where(releases: { status: 'YANKED' }) } - - # scope :for_channel_key, -> key { joins(artifact: :channel).where(release_channels: { key: }) } - # scope :stable, -> { for_channel_key(%i(stable)) } - # scope :rc, -> { for_channel_key(%i(stable rc)) } - # scope :beta, -> { for_channel_key(%i(stable rc beta)) } - # scope :alpha, -> { for_channel_key(%i(stable rc beta alpha)) } - # scope :dev, -> { for_channel_key(%i(dev)) } - - # scope :order_by_version, -> { - # joins(:release).reorder(<<~SQL.squish) - # releases.semver_major DESC, - # releases.semver_minor DESC NULLS LAST, - # releases.semver_patch DESC NULLS LAST, - # releases.semver_pre_word DESC NULLS FIRST, - # releases.semver_pre_num DESC NULLS LAST, - # releases.semver_build_word DESC NULLS LAST, - # releases.semver_build_num DESC NULLS LAST, - # release_specifications.created_at DESC - # SQL - # } + def as_gemspec = Gem::Specification.from_yaml(content) end