diff --git a/lib/r10k/module/base.rb b/lib/r10k/module/base.rb index 58172e135..1b0a3ed2d 100644 --- a/lib/r10k/module/base.rb +++ b/lib/r10k/module/base.rb @@ -99,6 +99,14 @@ def properties raise NotImplementedError end + # Return the module's cachedir. Subclasses that implement a cache + # will override this to return a real directory location. + # + # @return [String, :none] + def cachedir + :none + end + private def parse_title(title) diff --git a/lib/r10k/module/git.rb b/lib/r10k/module/git.rb index aabf0c05f..236b5c387 100644 --- a/lib/r10k/module/git.rb +++ b/lib/r10k/module/git.rb @@ -57,6 +57,10 @@ def status @repo.status(version) end + def cachedir + @repo.cache.sanitized_dirname + end + private def validate_ref(desired, default) diff --git a/lib/r10k/puppetfile.rb b/lib/r10k/puppetfile.rb index 6192eb489..fc522674d 100644 --- a/lib/r10k/puppetfile.rb +++ b/lib/r10k/puppetfile.rb @@ -143,7 +143,7 @@ def add_module(name, args) mod.origin = 'Puppetfile' @managed_content[install_path] << mod.name - cachedir = module_vcs_cachedir(mod) + cachedir = mod.cachedir @modules_by_vcs_cachedir[cachedir] ||= [] @modules_by_vcs_cachedir[cachedir] << mod @modules << mod @@ -189,19 +189,6 @@ def accept(visitor) private - def module_vcs_cachedir(mod) - if mod.respond_to? :repo - repo = mod.repo - if repo.respond_to? :cache - cache = repo.cache - if cache.respond_to? :sanitized_dirname - return cache.sanitized_dirname - end - end - end - :none - end - def serial_accept(visitor) visitor.visit(:puppetfile, self) do modules.each do |mod|