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

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/librarian/puppet/source/forge.rb,
lib/librarian/puppet/source/forge/repo.rb,
lib/librarian/puppet/source/forge/repo_v1.rb,
lib/librarian/puppet/source/forge/repo_v3.rb

Defined Under Namespace

Classes: Repo, RepoV1, RepoV3

Constant Summary collapse

LOCK_NAME =
'FORGE'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#clean_uri, #cp_r, #debug, #info, #module_name, #normalize_name, #rsync?, #warn

Constructor Details

#initialize(environment, uri, _options = {}) ⇒ Forge

Returns a new instance of Forge.



46
47
48
49
50
51
# File 'lib/librarian/puppet/source/forge.rb', line 46

def initialize(environment, uri, _options = {})
  self.environment = environment

  @uri = URI.parse(uri)
  @cache_path = nil
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



42
43
44
# File 'lib/librarian/puppet/source/forge.rb', line 42

def environment
  @environment
end

#uriObject (readonly)

Returns the value of attribute uri.



44
45
46
# File 'lib/librarian/puppet/source/forge.rb', line 44

def uri
  @uri
end

Class Method Details

.defaultObject



21
22
23
# File 'lib/librarian/puppet/source/forge.rb', line 21

def default
  @@default
end

.default=(source) ⇒ Object



17
18
19
# File 'lib/librarian/puppet/source/forge.rb', line 17

def default=(source)
  @@default = source
end

.from_lock_options(environment, options) ⇒ Object



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

def from_lock_options(environment, options)
  new(environment, options[:remote], options.reject { |k, _v| k == :remote })
end

.from_spec_args(environment, uri, options) ⇒ Object

Raises:

  • (Error)


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

def from_spec_args(environment, uri, options)
  recognised_options = []
  unrecognised_options = options.keys - recognised_options
  raise Error, "unrecognised options: #{unrecognised_options.join(', ')}" unless unrecognised_options.empty?

  new(environment, uri, options)
end

.lock_nameObject



25
26
27
# File 'lib/librarian/puppet/source/forge.rb', line 25

def lock_name
  LOCK_NAME
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



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

def ==(other)
  other &&
    self.class == other.class &&
    uri == other.uri
end

#cache_pathObject



103
104
105
106
107
108
# File 'lib/librarian/puppet/source/forge.rb', line 103

def cache_path
  @cache_path ||= begin
    dir = "#{uri.host}#{uri.path}".gsub(/[^0-9a-z\-_]/i, '_')
    environment.cache_path.join("source/puppet/forge/#{dir}")
  end
end

#fetch_dependencies(name, version, _version_uri) ⇒ Object



123
124
125
126
127
128
# File 'lib/librarian/puppet/source/forge.rb', line 123

def fetch_dependencies(name, version, _version_uri)
  repo(name).dependencies(version).map do |k, v|
    v = Librarian::Dependency::Requirement.new(v).to_gem_requirement
    Dependency.new(k, v, nil, name)
  end
end

#fetch_version(name, version_uri) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/librarian/puppet/source/forge.rb', line 114

def fetch_version(name, version_uri)
  versions = repo(name).versions
  if versions.include? version_uri
    version_uri
  else
    versions.first
  end
end

#hashObject



65
66
67
# File 'lib/librarian/puppet/source/forge.rb', line 65

def hash
  to_s.hash
end

#install!(manifest) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/librarian/puppet/source/forge.rb', line 83

def install!(manifest)
  manifest.source == self or raise ArgumentError

  debug { "Installing #{manifest}" }

  name = manifest.name
  version = manifest.version
  install_path = install_path(name)
  repo = repo(name)

  repo.install_version! version, install_path
end

#install_path(name) ⇒ Object



110
111
112
# File 'lib/librarian/puppet/source/forge.rb', line 110

def install_path(name)
  environment.install_path.join(module_name(name))
end

#manifest(name, version, dependencies) ⇒ Object



96
97
98
99
100
101
# File 'lib/librarian/puppet/source/forge.rb', line 96

def manifest(name, version, dependencies)
  manifest = Manifest.new(self, name)
  manifest.version = version
  manifest.dependencies = dependencies
  manifest
end

#manifests(name) ⇒ Object



130
131
132
# File 'lib/librarian/puppet/source/forge.rb', line 130

def manifests(name)
  repo(name).manifests
end

#pinned?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/librarian/puppet/source/forge.rb', line 77

def pinned?
  false
end

#to_lock_optionsObject



73
74
75
# File 'lib/librarian/puppet/source/forge.rb', line 73

def to_lock_options
  { remote: uri.to_s }
end

#to_sObject



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

def to_s
  clean_uri(uri).to_s
end

#to_spec_argsObject



69
70
71
# File 'lib/librarian/puppet/source/forge.rb', line 69

def to_spec_args
  [clean_uri(uri).to_s, {}]
end

#unpin!Object



81
# File 'lib/librarian/puppet/source/forge.rb', line 81

def unpin!; end