Class: Dependabot::Uv::FileUpdater::LockIndexCredentialMatcher

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/uv/file_updater/lock_index_credential_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(credentials:) ⇒ LockIndexCredentialMatcher

Returns a new instance of LockIndexCredentialMatcher.



14
15
16
# File 'lib/dependabot/uv/file_updater/lock_index_credential_matcher.rb', line 14

def initialize(credentials:)
  @credentials = credentials
end

Instance Method Details

#best_credential_for_registry_url(registry_url) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dependabot/uv/file_updater/lock_index_credential_matcher.rb', line 19

def best_credential_for_registry_url(registry_url)
  credential_scores = @credentials.map do |credential|
    [credential, credential_match_score(credential["index-url"].to_s, registry_url)]
  end
  best_match = credential_scores.max_by { |_, score| score }

  return nil unless best_match
  return nil if best_match[1].negative?

  best_match[0]
end