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.



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

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

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



111
112
113
# File 'lib/librarian/puppet/source/forge.rb', line 111

def environment
  @environment
end

#uriObject (readonly)

Returns the value of attribute uri.



113
114
115
# File 'lib/librarian/puppet/source/forge.rb', line 113

def uri
  @uri
end

Class Method Details

.from_lock_options(environment, options) ⇒ Object



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

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

.from_spec_args(environment, uri, options) ⇒ Object



100
101
102
103
104
105
106
107
108
# File 'lib/librarian/puppet/source/forge.rb', line 100

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



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

def lock_name
  LOCK_NAME
end

Instance Method Details

#==(other) ⇒ Object



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

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

#cache_pathObject



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

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



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

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



175
176
177
178
179
180
181
182
# File 'lib/librarian/puppet/source/forge.rb', line 175

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



146
147
148
149
150
151
152
153
154
155
# File 'lib/librarian/puppet/source/forge.rb', line 146

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



171
172
173
# File 'lib/librarian/puppet/source/forge.rb', line 171

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

#manifest(name, version, dependencies) ⇒ Object



157
158
159
160
161
162
# File 'lib/librarian/puppet/source/forge.rb', line 157

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

#manifests(name) ⇒ Object



190
191
192
# File 'lib/librarian/puppet/source/forge.rb', line 190

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

#pinned?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/librarian/puppet/source/forge.rb', line 139

def pinned?
  false
end

#to_lock_optionsObject



135
136
137
# File 'lib/librarian/puppet/source/forge.rb', line 135

def to_lock_options
  {:remote => uri}
end

#to_sObject



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

def to_s
  uri
end

#to_spec_argsObject



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

def to_spec_args
  [uri, {}]
end

#unpin!Object



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

def unpin!
end