Skip to content

Commit

Permalink
refactor gemspec parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Oct 22, 2024
1 parent 7c63a87 commit 7315b3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'rubygems/specification'
require 'compact_index'

module Api::V1::ReleaseEngines
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 3 additions & 28 deletions app/models/release_specification.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 7315b3e

Please sign in to comment.