Class: Gem::Guardian::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/gem/guardian/registry.rb

Overview

Enumerates gems visible through RubyGems-compatible registry sources.

This is intentionally a small library API rather than a supported CLI command. It is useful for research scripts that want to inspect the latest gem entries visible from the current Gem.sources configuration, including private RubyGems-compatible registries such as GitHub Packages, Gemfury, CodeArtifact, or self-hosted gem servers.

Defined Under Namespace

Classes: Entry

Instance Method Summary collapse

Constructor Details

#initialize(sources: Gem.sources, spec_fetcher: nil) ⇒ Registry

Returns a new instance of Registry.

Parameters:

  • sources (Gem::SourceList, Array<String, Gem::Source>) (defaults to: Gem.sources)

    registry sources to inspect

  • spec_fetcher (Gem::SpecFetcher) (defaults to: nil)

    RubyGems spec fetcher



26
27
28
29
# File 'lib/gem/guardian/registry.rb', line 26

def initialize(sources: Gem.sources, spec_fetcher: nil)
  @sources = normalize_sources(sources)
  @spec_fetcher = spec_fetcher || Gem::SpecFetcher.new(@sources)
end

Instance Method Details

#each_latest_spec(limit: nil) ⇒ Object

Yields latest gem entries visible from the configured sources.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gem/guardian/registry.rb', line 32

def each_latest_spec(limit: nil)
  return enum_for(:each_latest_spec, limit:) unless block_given?

  count = 0
  latest_spec_tuples.each do |spec, source|
    break if limit && count >= limit

    yield build_entry(spec, source)
    count += 1
  end
end

#latest_specs(limit: nil) ⇒ Object

Returns latest gem entries visible from the configured sources.



45
46
47
# File 'lib/gem/guardian/registry.rb', line 45

def latest_specs(limit: nil)
  each_latest_spec(limit:).to_a
end