class Librarian::Puppet::Source::Forge

Constants

LOCK_NAME

Attributes

environment[RW]
uri[R]

Public Class Methods

client_api_version() click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 41
def client_api_version()
  version = 1
  pe_version = Librarian::Puppet.puppet_version.match(/\(Puppet Enterprise (.+)\)/)

  # Puppet 3.6.0+ uses api v3
  if Librarian::Puppet::puppet_gem_version >= Gem::Version.create('3.6.0.a')
    version = 3
  # Puppet enterprise 3.2.0+ uses api v3
  elsif pe_version and Gem::Version.create(pe_version[1].strip) >= Gem::Version.create('3.2.0')
    version = 3
  end
  return version
end
default() click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 19
def default
  @@default
end
default=(source) click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 15
def default=(source)
  @@default = source
end
from_lock_options(environment, options) click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 27
def from_lock_options(environment, options)
  new(environment, options[:remote], options.reject { |k, v| k == :remote })
end
from_spec_args(environment, uri, options) click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 31
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_name() click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 23
def lock_name
  LOCK_NAME
end
new(environment, uri, options = {}) click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 61
def initialize(environment, uri, options = {})
  self.environment = environment

  if uri =~ %r{^http(s)?://forge\.puppetlabs\.com}
    uri = "https://forgeapi.puppetlabs.com"
    warn { "Replacing Puppet Forge API URL to use v3 #{uri}. You should update your Puppetfile" }
  end

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

Public Instance Methods

==(other) click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 77
def ==(other)
  other &&
  self.class == other.class &&
  self.uri == other.uri
end
Also aliased as: eql?
cache_path() click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 124
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
eql?(other)
Alias for: ==
fetch_dependencies(name, version, version_uri) click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 144
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) click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 135
def fetch_version(name, version_uri)
  versions = repo(name).versions
  if versions.include? version_uri
    version_uri
  else
    versions.first
  end
end
hash() click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 85
def hash
  self.to_s.hash
end
install!(manifest) click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 104
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) click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 131
def install_path(name)
  environment.install_path.join(module_name(name))
end
manifest(name, version, dependencies) click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 117
def manifest(name, version, dependencies)
  manifest = Manifest.new(self, name)
  manifest.version = version
  manifest.dependencies = dependencies
  manifest
end
manifests(name) click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 151
def manifests(name)
  repo(name).manifests
end
pinned?() click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 97
def pinned?
  false
end
to_lock_options() click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 93
def to_lock_options
  {:remote => clean_uri(uri).to_s}
end
to_s() click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 73
def to_s
  clean_uri(uri).to_s
end
to_spec_args() click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 89
def to_spec_args
  [clean_uri(uri).to_s, {}]
end
unpin!() click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 101
def unpin!
end

Private Instance Methods

repo(name) click to toggle source
# File lib/librarian/puppet/source/forge.rb, line 157
def repo(name)
  @repo ||= {}

  unless @repo[name]
    # If we are using the official Forge then use API v3, otherwise use the preferred api
    # as defined by the CLI option use_v1_api
    if uri.hostname =~ /\.puppetlabs\.com$/ || !environment.use_v1_api
      @repo[name] = RepoV3.new(self, name)
    else
      @repo[name] = RepoV1.new(self, name)
    end
  end
  @repo[name]
end