Class: PuppetForge::V3::ModuleRelease
- Inherits:
-
Object
- Object
- PuppetForge::V3::ModuleRelease
- Includes:
- Connection
- Defined in:
- lib/shared/puppet_forge/v3/module_release.rb
Overview
Access metadata and downloads for a specific module release.
Defined Under Namespace
Classes: ChecksumMismatch
Constant Summary
Constants included from Connection
Instance Attribute Summary collapse
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Attributes included from Connection
Instance Method Summary collapse
-
#data ⇒ Hash
The complete Forge response for this release.
-
#download(path) ⇒ void
Download this module release to the specified path.
-
#initialize(full_name, version) ⇒ ModuleRelease
constructor
A new instance of ModuleRelease.
-
#slug ⇒ String
The unique identifier for this module release.
-
#verify(path) ⇒ void
Verify that a downloaded module matches the checksum in the metadata for this release.
Methods included from Connection
authorization, authorization=, #make_connection
Constructor Details
#initialize(full_name, version) ⇒ ModuleRelease
Returns a new instance of ModuleRelease.
23 24 25 26 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 23 def initialize(full_name, version) @full_name = PuppetForge::V3.normalize_name(full_name) @version = version end |
Instance Attribute Details
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
14 15 16 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 14 def full_name @full_name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
18 19 20 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 18 def version @version end |
Instance Method Details
#data ⇒ Hash
Returns The complete Forge response for this release.
29 30 31 32 33 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 29 def data @data ||= conn.get(resource_url).body rescue Faraday::ResourceNotFound => e raise PuppetForge::ModuleReleaseNotFound, "The module release #{slug} does not exist on #{conn.url_prefix}.", e.backtrace end |
#download(path) ⇒ void
This method returns an undefined value.
Download this module release to the specified path.
44 45 46 47 48 49 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 44 def download(path) resp = conn.get(file_url) path.open('wb') { |fh| fh.write(resp.body) } rescue Faraday::ResourceNotFound => e raise PuppetForge::ModuleReleaseNotFound, "The module release #{slug} does not exist on #{conn.url_prefix}.", e.backtrace end |
#slug ⇒ String
Returns The unique identifier for this module release.
36 37 38 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 36 def slug "#{full_name}-#{version}" end |
#verify(path) ⇒ void
This method returns an undefined value.
Verify that a downloaded module matches the checksum in the metadata for this release.
55 56 57 58 59 60 61 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 55 def verify(path) expected_md5 = data['file_md5'] file_md5 = Digest::MD5.file(path).hexdigest if expected_md5 != file_md5 raise ChecksumMismatch.new("Expected #{path} checksum to be #{expected_md5}, got #{file_md5}") end end |