Class: BuildpackSupport::Repository::RepositoryIndex

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

Overview

A repository index represents the index of repository containing various versions of a file.

Instance Method Summary collapse

Constructor Details

#initialize(repository_root, version_resolver = WildcardVersionResolver.new) ⇒ RepositoryIndex

Creates a new repository index, populating it with values from an index file.

Parameters:

  • repository_root (String)

    the root of the repository to create the index for

  • version_resolver (VersionResolver) (defaults to: WildcardVersionResolver.new)

    the version resolver to use when finding items



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

def initialize(repository_root, version_resolver = WildcardVersionResolver.new)
  @logger           = BuildpackSupport::Logging::LoggerFactory.instance.get_logger RepositoryIndex
  @version_resolver = version_resolver

  default_repository_root = BuildpackSupport::ConfigurationUtils.new.load('repository')['default_repository_root'].chomp('/')
  cache.get("#{canonical default_repository_root, repository_root}#{INDEX_PATH}") do |file|
    @index = YAML.load_file(file)
    @logger.debug { @index }
  end
end

Instance Method Details

#find_item(version) ⇒ TokenizedVersion, String

Finds a version of the file matching the given, possibly wildcarded, version.

Parameters:

  • version (String)

    the possibly wildcarded version to find

Returns:



50
51
52
53
54
# File 'lib/buildpack_support/repository/repository_index.rb', line 50

def find_item(version)
  version = @version_resolver.resolve(version, @index.keys)
  uri     = @index[version.to_s]
  [version, uri]
end