Class: Gem::Guardian::ChecksumProvider::SourceScoped

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

Overview

Restricts another checksum provider to dependencies resolved from a matching gem source.

This lets project configuration attach publisher checksum URLs to a private registry without probing that URL for every public gem. Source matching is prefix-based after trailing slashes are normalized, so a configured source such as https://gems.contribsys.com/ matches locked dependency sources under that registry.

Instance Method Summary collapse

Constructor Details

#initialize(source:, provider:) ⇒ SourceScoped

Returns a new instance of SourceScoped.

Parameters:

  • source (String)

    source URI prefix this provider applies to

  • provider (#checksum_for)

    checksum provider to delegate to



72
73
74
75
# File 'lib/gem/guardian/checksum_provider.rb', line 72

def initialize(source:, provider:)
  @source = normalize_source(source)
  @provider = provider
end

Instance Method Details

#checksum_for(dependency, client:) ⇒ Result?

Returns delegated checksum result when the source matches, otherwise +nil+.

Parameters:

  • dependency (Dependency)

    dependency whose source should be checked

  • client (RubygemsClient)

    client passed to the delegated provider

Returns:

  • (Result, nil)

    delegated checksum result when the source matches, otherwise +nil+



80
81
82
83
84
# File 'lib/gem/guardian/checksum_provider.rb', line 80

def checksum_for(dependency, client:)
  return unless source_matches?(dependency.source)

  @provider.checksum_for(dependency, client:)
end