Class: BuildpackSupport::Repository::WildcardVersionResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/buildpack_support/repository/wildcard_version_resolver.rb

Overview

A resolver that selects values from a collection based on a set of rules governing wildcards

Instance Method Summary collapse

Instance Method Details

#resolve(candidate_version, versions) ⇒ TokenizedVersion

Resolves a version from a collection of versions. The candidate_version must be structured like:

* up to three numeric components, followed by an optional string component
* the final component may be a +

The resolution returns the maximum of the versions that match the candidate version

Parameters:

  • candidate_version (TokenizedVersion)

    the version, possibly containing a wildcard, to resolve. If nil, substituted with +.

  • versions (Array<String>)

    the collection of versions to resolve against

Returns:

Raises:

  • if no version can be resolved



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/buildpack_support/repository/wildcard_version_resolver.rb', line 35

def resolve(candidate_version, versions)
  tokenized_candidate_version = safe_candidate_version candidate_version
  tokenized_versions          = versions.map { |version| BuildpackSupport::TokenizedVersion.new(version, false) }

  version = tokenized_versions
  .select { |tokenized_version| matches? tokenized_candidate_version, tokenized_version }
  .max { |a, b| a <=> b }

  fail "No version resolvable for '#{candidate_version}' in #{versions.join(', ')}" if version.nil?
  version
end