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

Inherits:
Object
  • Object
show all
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

Constructor Details

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

Returns a new instance of Forge.



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

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

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



202
203
204
# File 'lib/librarian/puppet/source/forge.rb', line 202

def environment
  @environment
end

#uriObject (readonly)

Returns the value of attribute uri.



204
205
206
# File 'lib/librarian/puppet/source/forge.rb', line 204

def uri
  @uri
end

Class Method Details

.from_lock_options(environment, options) ⇒ Object



187
188
189
# File 'lib/librarian/puppet/source/forge.rb', line 187

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

.from_spec_args(environment, uri, options) ⇒ Object



191
192
193
194
195
196
197
198
199
# File 'lib/librarian/puppet/source/forge.rb', line 191

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



183
184
185
# File 'lib/librarian/puppet/source/forge.rb', line 183

def lock_name
  LOCK_NAME
end

Instance Method Details

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



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

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

#cache_pathObject



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

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



286
287
288
289
290
291
292
293
294
295
296
# File 'lib/librarian/puppet/source/forge.rb', line 286

def fetch_dependencies(name, version, version_uri)
  environment.logger.debug { "      Fetching dependencies for #{name} #{version}" }
  repo(name).dependencies(version).map do |k, v|
    begin
      v = Requirement.new(v).gem_requirement
      Dependency.new(k, v, nil)
    rescue ArgumentError => e
      raise Error, "Error fetching dependency for #{name} [#{version}]: #{k} [#{v}]: #{e}"
    end
  end
end

#fetch_version(name, version_uri) ⇒ Object



277
278
279
280
281
282
283
284
# File 'lib/librarian/puppet/source/forge.rb', line 277

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

#hashObject



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

def hash
  self.uri.hash
end

#install!(manifest) ⇒ Object



248
249
250
251
252
253
254
255
256
257
# File 'lib/librarian/puppet/source/forge.rb', line 248

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



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

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

#manifest(name, version, dependencies) ⇒ Object



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

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

#manifests(name) ⇒ Object



298
299
300
# File 'lib/librarian/puppet/source/forge.rb', line 298

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

#pinned?Boolean

Returns:

  • (Boolean)


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

def pinned?
  false
end

#to_lock_optionsObject



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

def to_lock_options
  {:remote => uri}
end

#to_sObject



212
213
214
# File 'lib/librarian/puppet/source/forge.rb', line 212

def to_s
  uri
end

#to_spec_argsObject



233
234
235
# File 'lib/librarian/puppet/source/forge.rb', line 233

def to_spec_args
  [uri, {}]
end

#unpin!Object



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

def unpin!
end