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

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

Defined Under Namespace

Classes: Repo

Constant Summary collapse

LOCK_NAME =
'FORGE'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#cp_r, #debug, #info

Constructor Details

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

Returns a new instance of Forge.



218
219
220
221
222
# File 'lib/librarian/puppet/source/forge.rb', line 218

def initialize(environment, uri, options = {})
  self.environment = environment
  @uri = uri
  @cache_path = nil
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



214
215
216
# File 'lib/librarian/puppet/source/forge.rb', line 214

def environment
  @environment
end

#uriObject (readonly)

Returns the value of attribute uri.



216
217
218
# File 'lib/librarian/puppet/source/forge.rb', line 216

def uri
  @uri
end

Class Method Details

.from_lock_options(environment, options) ⇒ Object



199
200
201
# File 'lib/librarian/puppet/source/forge.rb', line 199

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

.from_spec_args(environment, uri, options) ⇒ Object



203
204
205
206
207
208
209
210
211
# File 'lib/librarian/puppet/source/forge.rb', line 203

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

  new(environment, uri, options)
end

.lock_nameObject



195
196
197
# File 'lib/librarian/puppet/source/forge.rb', line 195

def lock_name
  LOCK_NAME
end

Instance Method Details

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



228
229
230
231
232
# File 'lib/librarian/puppet/source/forge.rb', line 228

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

#cache_pathObject



273
274
275
276
277
278
# File 'lib/librarian/puppet/source/forge.rb', line 273

def cache_path
  @cache_path ||= begin
    dir = Digest::MD5.hexdigest(uri)
    environment.cache_path.join("source/puppet/forge/#{dir}")
  end
end

#fetch_dependencies(name, version, version_uri) ⇒ Object



293
294
295
296
297
298
# File 'lib/librarian/puppet/source/forge.rb', line 293

def fetch_dependencies(name, version, version_uri)
  repo(name).dependencies(version).map do |k, v|
    v = Requirement.new(v).gem_requirement
    Dependency.new(k, v, nil)
  end
end

#fetch_version(name, version_uri) ⇒ Object



284
285
286
287
288
289
290
291
# File 'lib/librarian/puppet/source/forge.rb', line 284

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

#hashObject



236
237
238
# File 'lib/librarian/puppet/source/forge.rb', line 236

def hash
  self.to_s.hash
end

#install!(manifest) ⇒ Object



255
256
257
258
259
260
261
262
263
264
# File 'lib/librarian/puppet/source/forge.rb', line 255

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

  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



280
281
282
# File 'lib/librarian/puppet/source/forge.rb', line 280

def install_path(name)
  environment.install_path.join(name.split('/').last)
end

#manifest(name, version, dependencies) ⇒ Object



266
267
268
269
270
271
# File 'lib/librarian/puppet/source/forge.rb', line 266

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

#manifests(name) ⇒ Object



300
301
302
# File 'lib/librarian/puppet/source/forge.rb', line 300

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

#pinned?Boolean

Returns:

  • (Boolean)


248
249
250
# File 'lib/librarian/puppet/source/forge.rb', line 248

def pinned?
  false
end

#to_lock_optionsObject



244
245
246
# File 'lib/librarian/puppet/source/forge.rb', line 244

def to_lock_options
  {:remote => uri}
end

#to_sObject



224
225
226
# File 'lib/librarian/puppet/source/forge.rb', line 224

def to_s
  uri
end

#to_spec_argsObject



240
241
242
# File 'lib/librarian/puppet/source/forge.rb', line 240

def to_spec_args
  [uri, {}]
end

#unpin!Object



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

def unpin!
end