Class: Toys::Utils::GitCache
- Inherits:
-
Object
- Object
- Toys::Utils::GitCache
- Defined in:
- 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 availble 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.
This class is used by the Loader to load tools from git. Tools can also
use the :git_cache
mixin for direct access to this class.
Defined Under Namespace
Classes: Error, RefInfo, RepoInfo, SourceInfo
Instance Attribute Summary collapse
-
#cache_dir ⇒ String
readonly
The cache directory.
Instance Method Summary collapse
-
#get(remote, path: nil, commit: nil, into: nil, update: false, timestamp: nil) ⇒ String
(also: #find)
Get the given git-based files from the git cache, loading from the remote repo if necessary.
-
#initialize(cache_dir: nil) ⇒ GitCache
constructor
Access a git cache.
-
#remotes ⇒ Array<String>
Returns an array of the known remote names.
-
#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. -
#remove_repos(remotes) ⇒ Array<String>
Removes caches for the given repos, or all repos if specified.
-
#remove_sources(remote, commits: nil) ⇒ Array<SourceInfo>?
Removes shared sources for the given cache.
-
#repo_info(remote) ⇒ RepoInfo?
Returns a RepoInfo describing the cache for the given remote, or
nil
if the given remote has never been cached.
Constructor Details
#initialize(cache_dir: nil) ⇒ GitCache
Access a git cache.
228 229 230 |
# File 'core-docs/toys/utils/git_cache.rb', line 228 def initialize(cache_dir: nil) # Source available in the toys-core gem end |
Instance Attribute Details
#cache_dir ⇒ String (readonly)
The cache directory.
237 238 239 |
# File 'core-docs/toys/utils/git_cache.rb', line 237 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 :info
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.
272 273 274 |
# File 'core-docs/toys/utils/git_cache.rb', line 272 def get(remote, path: nil, commit: nil, into: nil, update: false, timestamp: nil) # Source available in the toys-core gem end |
#remotes ⇒ Array<String>
Returns an array of the known remote names.
282 283 284 |
# File 'core-docs/toys/utils/git_cache.rb', line 282 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.
328 329 330 |
# File 'core-docs/toys/utils/git_cache.rb', line 328 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 GitCache clients.
311 312 313 |
# File 'core-docs/toys/utils/git_cache.rb', line 311 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 GitCache clients.
348 349 350 |
# File 'core-docs/toys/utils/git_cache.rb', line 348 def remove_sources(remote, commits: nil) # Source available in the toys-core gem end |