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.



61
62
63
64
65
66
67
68
69
70
71
# 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

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



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

def environment
  @environment
end

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end

Class Method Details

.client_api_versionObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# 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

.defaultObject



19
20
21
# File 'lib/librarian/puppet/source/forge.rb', line 19

def default
  @@default
end

.default=(source) ⇒ Object



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

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

.from_lock_options(environment, options) ⇒ Object



27
28
29
# 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) ⇒ Object



31
32
33
34
35
36
37
38
39
# 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_nameObject



23
24
25
# File 'lib/librarian/puppet/source/forge.rb', line 23

def lock_name
  LOCK_NAME
end

Instance Method Details

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



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

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

#cache_pathObject



124
125
126
127
128
129
# 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

#fetch_dependencies(name, version, version_uri) ⇒ Object



144
145
146
147
148
149
# 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)
  end
end

#fetch_version(name, version_uri) ⇒ Object



135
136
137
138
139
140
141
142
# 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

#hashObject



85
86
87
# File 'lib/librarian/puppet/source/forge.rb', line 85

def hash
  self.to_s.hash
end

#install!(manifest) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
# 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) ⇒ Object



131
132
133
# 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) ⇒ Object



117
118
119
120
121
122
# 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) ⇒ Object



151
152
153
# File 'lib/librarian/puppet/source/forge.rb', line 151

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

#pinned?Boolean

Returns:

  • (Boolean)


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

def pinned?
  false
end

#to_lock_optionsObject



93
94
95
# File 'lib/librarian/puppet/source/forge.rb', line 93

def to_lock_options
  {:remote => clean_uri(uri).to_s}
end

#to_sObject



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

def to_s
  clean_uri(uri).to_s
end

#to_spec_argsObject



89
90
91
# File 'lib/librarian/puppet/source/forge.rb', line 89

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

#unpin!Object



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

def unpin!
end