Class: Toys::Utils::GitCache
- Inherits:
-
Object
- Object
- Toys::Utils::GitCache
- Defined in:
- lib/toys/utils/git_cache.rb
Overview
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 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
Instance Attribute Summary collapse
-
#cache_dir ⇒ String
readonly
The cache directory.
Instance Method Summary collapse
-
#find(remote, path: nil, commit: nil, update: false) ⇒ String
Find 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.
Constructor Details
Instance Attribute Details
#cache_dir ⇒ String (readonly)
The cache directory.
86 87 88 |
# File 'lib/toys/utils/git_cache.rb', line 86 def cache_dir @cache_dir end |
Instance Method Details
#find(remote, path: nil, commit: nil, update: false) ⇒ String
Find the given git-based files from the git cache, loading from the remote repo if necessary.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/toys/utils/git_cache.rb', line 70 def find(remote, path: nil, commit: nil, update: false) path ||= "" commit ||= "HEAD" dir = ensure_dir(remote) lock_repo(dir) do ensure_repo(dir, remote) sha = ensure_commit(dir, commit, update) ensure_source(dir, sha, path.to_s) end end |