Class: R10K::Git::Cache Abstract
- Inherits:
-
Object
- Object
- R10K::Git::Cache
- Extended by:
- Forwardable
- Includes:
- Logging, Settings::Mixin
- Defined in:
- lib/r10k/git/cache.rb
Overview
Cache Git repository mirrors for object database reuse.
This implements most of the behavior needed for Git repo caching, but needs to have a specific Git bare repository provided. Subclasses should implement the Cache.bare_repository method.
Direct Known Subclasses
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
- #path ⇒ Object readonly
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Class Method Summary collapse
-
.bare_repository ⇒ Object
abstract
The concrete bare repository implementation to use for interacting with the cached Git repository.
-
.generate(remote) ⇒ R10K::Git::Cache
Generate a new instance with the given remote or return an existing object with the given remote.
- .instance_cache ⇒ Object private
Instance Method Summary collapse
-
#initialize(remote) ⇒ Cache
constructor
A new instance of Cache.
- #reset! ⇒ Object private
-
#sanitized_dirname ⇒ Object
Reformat the remote name into something that can be used as a directory.
- #sync ⇒ Object
- #sync! ⇒ Object
- #synced? ⇒ Boolean
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Methods included from Settings::Mixin
Constructor Details
#initialize(remote) ⇒ Cache
Returns a new instance of Cache.
74 75 76 77 |
# File 'lib/r10k/git/cache.rb', line 74 def initialize(remote) @remote = remote @repo = self.class..new(settings[:cache_root], sanitized_dirname) end |
Instance Attribute Details
#path ⇒ Object (readonly)
64 65 66 67 |
# File 'lib/r10k/git/cache.rb', line 64 def path logger.warn _("%{class}#path is deprecated; use #git_dir") % {class: self.class} git_dir end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
71 72 73 |
# File 'lib/r10k/git/cache.rb', line 71 def repo @repo end |
Class Method Details
.bare_repository ⇒ Object
Returns The concrete bare repository implementation to use for interacting with the cached Git repository.
51 52 53 |
# File 'lib/r10k/git/cache.rb', line 51 def self. raise NotImplementedError end |
.generate(remote) ⇒ R10K::Git::Cache
Generate a new instance with the given remote or return an existing object with the given remote. This should be used over R10K::Git::Cache.new.
44 45 46 |
# File 'lib/r10k/git/cache.rb', line 44 def self.generate(remote) instance_cache.generate(remote) end |
.instance_cache ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 |
# File 'lib/r10k/git/cache.rb', line 34 def self.instance_cache @instance_cache end |
Instance Method Details
#reset! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
106 107 108 |
# File 'lib/r10k/git/cache.rb', line 106 def reset! @synced = false end |
#sanitized_dirname ⇒ Object
Reformat the remote name into something that can be used as a directory
113 114 115 |
# File 'lib/r10k/git/cache.rb', line 113 def sanitized_dirname @sanitized_dirname ||= @remote.gsub(/(\w+:\/\/)(.*)(@)/, '\1').gsub(/[^@\w\.-]/, '-') end |
#sync ⇒ Object
79 80 81 82 83 84 |
# File 'lib/r10k/git/cache.rb', line 79 def sync if !@synced sync! @synced = true end end |
#sync! ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/r10k/git/cache.rb', line 90 def sync! if cached? @repo.fetch else logger.debug1 _("Creating new git cache for %{remote}") % {remote: @remote.inspect} # TODO extract this to an initialization step if !File.exist?(settings[:cache_root]) FileUtils.mkdir_p settings[:cache_root] end @repo.clone(@remote) end end |
#synced? ⇒ Boolean
86 87 88 |
# File 'lib/r10k/git/cache.rb', line 86 def synced? @synced end |