Class: Librarian::Puppet::Source::Forge::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/librarian/puppet/source/forge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, name) ⇒ Repo

Returns a new instance of Repo.



14
15
16
17
# File 'lib/librarian/puppet/source/forge.rb', line 14

def initialize(source, name)
  self.source = source
  self.name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/librarian/puppet/source/forge.rb', line 11

def name
  @name
end

#sourceObject

Returns the value of attribute source.



11
12
13
# File 'lib/librarian/puppet/source/forge.rb', line 11

def source
  @source
end

Instance Method Details

#cache_pathObject



54
55
56
# File 'lib/librarian/puppet/source/forge.rb', line 54

def cache_path
  @cache_path ||= source.cache_path.join(name)
end

#cache_version_unpacked!(version) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/librarian/puppet/source/forge.rb', line 66

def cache_version_unpacked!(version)
  path = version_unpacked_cache_path(version)
  return if path.directory?

  path.mkpath

  output = `puppet module install -i #{path.to_s} --modulepath #{path.to_s} --ignore-dependencies #{name} 2>&1`
end

#dependencies(version) ⇒ Object



28
29
30
31
# File 'lib/librarian/puppet/source/forge.rb', line 28

def dependencies(version)
  data = api_call("api/v1/releases.json?module=#{name}&version=#{version}")
  data[name].first['dependencies']
end

#environmentObject



50
51
52
# File 'lib/librarian/puppet/source/forge.rb', line 50

def environment
  source.environment
end

#hexdigest(value) ⇒ Object



62
63
64
# File 'lib/librarian/puppet/source/forge.rb', line 62

def hexdigest(value)
  Digest::MD5.hexdigest(value)
end

#install_version!(version, install_path) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/librarian/puppet/source/forge.rb', line 39

def install_version!(version, install_path)
  cache_version_unpacked! version

  if install_path.exist?
    install_path.rmtree
  end

  unpacked_path = version_unpacked_cache_path(version).join(name.split('/').last)
  FileUtils.cp_r(unpacked_path, install_path)
end

#manifestsObject



33
34
35
36
37
# File 'lib/librarian/puppet/source/forge.rb', line 33

def manifests
  versions.map do |version|
    Manifest.new(source, name, version)
  end
end

#version_unpacked_cache_path(version) ⇒ Object



58
59
60
# File 'lib/librarian/puppet/source/forge.rb', line 58

def version_unpacked_cache_path(version)
  cache_path.join('version').join(hexdigest(version.to_s))
end

#versionsObject



19
20
21
22
23
24
25
26
# File 'lib/librarian/puppet/source/forge.rb', line 19

def versions
  data = api_call("#{name}.json")
  if data.nil?
    raise Error, "Unable to find module '#{name}' on #{source}"
  end

  data['releases'].map { |r| r['version'] }.sort.reverse
end