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

Inherits:
Object
  • Object
show all
Includes:
Helpers::Debug
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.



121
122
123
124
125
# File 'lib/librarian/puppet/source/forge.rb', line 121

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

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



117
118
119
# File 'lib/librarian/puppet/source/forge.rb', line 117

def environment
  @environment
end

#uriObject (readonly)

Returns the value of attribute uri.



119
120
121
# File 'lib/librarian/puppet/source/forge.rb', line 119

def uri
  @uri
end

Class Method Details

.from_lock_options(environment, options) ⇒ Object



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

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

.from_spec_args(environment, uri, options) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/librarian/puppet/source/forge.rb', line 106

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



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

def lock_name
  LOCK_NAME
end

Instance Method Details

#==(other) ⇒ Object



131
132
133
134
135
# File 'lib/librarian/puppet/source/forge.rb', line 131

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

#cache_pathObject



172
173
174
175
176
177
# File 'lib/librarian/puppet/source/forge.rb', line 172

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



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

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

#fetch_version(name, version_uri) ⇒ Object



183
184
185
186
187
188
189
190
# File 'lib/librarian/puppet/source/forge.rb', line 183

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

#install!(manifest) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/librarian/puppet/source/forge.rb', line 152

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

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

  debug { "Installing #{manifest}" }

  repo.install_version! version, install_path
end

#install_path(name) ⇒ Object



179
180
181
# File 'lib/librarian/puppet/source/forge.rb', line 179

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

#manifest(name, version, dependencies) ⇒ Object



165
166
167
168
169
170
# File 'lib/librarian/puppet/source/forge.rb', line 165

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

#manifests(name) ⇒ Object



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

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

#pinned?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/librarian/puppet/source/forge.rb', line 145

def pinned?
  false
end

#to_lock_optionsObject



141
142
143
# File 'lib/librarian/puppet/source/forge.rb', line 141

def to_lock_options
  {:remote => uri}
end

#to_sObject



127
128
129
# File 'lib/librarian/puppet/source/forge.rb', line 127

def to_s
  uri
end

#to_spec_argsObject



137
138
139
# File 'lib/librarian/puppet/source/forge.rb', line 137

def to_spec_args
  [uri, {}]
end

#unpin!Object



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

def unpin!
end