Skip to content

Commit

Permalink
[puppetlabs#1058] Add accessor for a module's cachedir
Browse files Browse the repository at this point in the history
  • Loading branch information
Magisus committed Jul 24, 2020
1 parent 5733db7 commit bffb908
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
8 changes: 8 additions & 0 deletions lib/r10k/module/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions lib/r10k/module/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def status
@repo.status(version)
end

def cachedir
@repo.cache.sanitized_dirname
end

private

def validate_ref(desired, default)
Expand Down
15 changes: 1 addition & 14 deletions lib/r10k/puppetfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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|
Expand Down

0 comments on commit bffb908

Please sign in to comment.