Class: Toys::Utils::GitCache

Inherits:
Object
  • Object
show all
Defined in:
core-docs/toys/utils/git_cache.rb,
core-docs/toys/utils/git_cache.rb,
core-docs/toys/utils/git_cache.rb,
core-docs/toys/utils/git_cache.rb,
core-docs/toys/utils/git_cache.rb

Overview

Defined in the toys-core gem

This object provides cached access to remote git data. Given a remote repository, a path, and a commit, it makes the files available in the local filesystem. Access is cached, so repeated requests for the same commit and path in the same repo do not hit the remote repository again.

Defined Under Namespace

Classes: Error, RefInfo, RepoInfo, SourceInfo

Constant Summary collapse

VERSION =

Version of the git_cache gem

Returns:

  • (String)
"0.1.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_dir: nil) ⇒ GitCache

Access a git cache.

Parameters:

  • cache_dir (String) (defaults to: nil)

    The path to the cache directory. Defaults to a specific directory in the user's XDG cache.



21
22
23
# File 'core-docs/toys/utils/git_cache.rb', line 21

def initialize(cache_dir: nil)
  # Source available in the toys-core gem
end

Instance Attribute Details

#cache_dirString (readonly)

The cache directory.

Returns:

  • (String)


30
31
32
# File 'core-docs/toys/utils/git_cache.rb', line 30

def cache_dir
  @cache_dir
end

Instance Method Details

#get(remote, path: nil, commit: nil, into: nil, update: false, timestamp: nil) ⇒ String Also known as: find

Get the given git-based files from the git cache, loading from the remote repo if necessary.

The resulting files are either copied into a directory you provide in the :into parameter, or populated into a shared source directory if you omit the :into parameter. In the latter case, it is important that you do not modify the returned files or directories, nor add or remove any files from the directories returned, to avoid confusing callers that could be given the same directory. If you need to make any modifications to the returned files, use :into to provide your own private directory.

Parameters:

  • remote (String)

    The URL of the git repo. Required.

  • path (String) (defaults to: nil)

    The path to the file or directory within the repo. Optional. Defaults to the entire repo.

  • commit (String) (defaults to: nil)

    The commit reference, which may be a SHA or any git ref such as a branch or tag. Optional. Defaults to HEAD.

  • into (String) (defaults to: nil)

    If provided, copies the specified files into the given directory path. If omitted or nil, populates and returns a shared source file or directory.

  • update (boolean, Integer) (defaults to: false)

    Whether to update non-SHA commit references if they were previously loaded. This is useful, for example, if the commit is HEAD or a branch name. Pass true or false to specify whether to update, or an integer to update if last update was done at least that many seconds ago. Default is false.

  • timestamp (Integer, nil) (defaults to: nil)

    The timestamp for recording the access time and determining whether a resource is stale. Normally, you should leave this out and it will default to the current time.

Returns:

  • (String)

    The full path to the cached files. The returned path will correspond to the path given. For example, if you provide the path Gemfile representing a single file in the repository, the returned path will point directly to the cached copy of that file.



68
69
70
# File 'core-docs/toys/utils/git_cache.rb', line 68

def get(remote, path: nil, commit: nil, into: nil, update: false, timestamp: nil)
  # Source available in the toys-core gem
end

#remotesArray<String>

Returns an array of the known remote names.

Returns:

  • (Array<String>)


78
79
80
# File 'core-docs/toys/utils/git_cache.rb', line 78

def remotes
  # Source available in the toys-core gem
end

#remove_refs(remote, refs: nil) ⇒ Array<RefInfo>?

Remove records of the given refs (i.e. branches, tags, or HEAD) from the given repository's cache. The next time those refs are requested, they will be pulled from the remote repo.

If you provide the refs: argument, only those refs are removed. Otherwise, all refs are removed.

Parameters:

  • remote (String)

    The repository

  • refs (Array<String>) (defaults to: nil)

    The refs to remove. Optional.

Returns:

  • (Array<RefInfo>, nil)

    The refs actually forgotten, or nil if the given repo is not in the cache.



125
126
127
# File 'core-docs/toys/utils/git_cache.rb', line 125

def remove_refs(remote, refs: nil)
  # Source available in the toys-core gem
end

#remove_repos(remotes) ⇒ Array<String>

Removes caches for the given repos, or all repos if specified.

Removes all cache information for the specified repositories, including local clones and shared source directories. The next time these repositories are requested, they will be reloaded from the remote repository from scratch.

Be careful not to remove repos that are currently in use by other Toys::Utils::GitCache clients.

Parameters:

  • remotes (Array<String>, :all, nil)

    The remotes to remove. If set to :all or nil, removes all repos.

Returns:

  • (Array<String>)

    The remotes actually removed.



108
109
110
# File 'core-docs/toys/utils/git_cache.rb', line 108

def remove_repos(remotes)
  # Source available in the toys-core gem
end

#remove_sources(remote, commits: nil) ⇒ Array<SourceInfo>?

Removes shared sources for the given cache. The next time a client requests them, the removed sources will be recopied from the repo.

If you provide the commits: argument, only sources associated with those commits are removed. Otherwise, all sources are removed.

Be careful not to remove sources that are currently in use by other Toys::Utils::GitCache clients.

Parameters:

  • remote (String)

    The repository

  • commits (Array<String>) (defaults to: nil)

    Remove only the sources for the given commits. Optional.

Returns:

  • (Array<SourceInfo>, nil)

    The sources actually removed, or nil if the given repo is not in the cache.



145
146
147
# File 'core-docs/toys/utils/git_cache.rb', line 145

def remove_sources(remote, commits: nil)
  # Source available in the toys-core gem
end

#repo_info(remote) ⇒ RepoInfo?

Returns a RepoInfo describing the cache for the given remote, or nil if the given remote has never been cached.

Parameters:

  • remote (String)

    Remote name for a repo

Returns:



89
90
91
# File 'core-docs/toys/utils/git_cache.rb', line 89

def repo_info(remote)
  # Source available in the toys-core gem
end