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 resposne 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.
22 23 24 25 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 22 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.
13 14 15 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 13 def full_name @full_name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
17 18 19 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 17 def version @version end |
Instance Method Details
#data ⇒ Hash
Returns The complete Forge resposne for this release.
28 29 30 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 28 def data @data ||= conn.get(resource_url).body end |
#download(path) ⇒ void
This method returns an undefined value.
Download this module release to the specified path.
41 42 43 44 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 41 def download(path) resp = conn.get(file_url) path.open('wb') { |fh| fh.write(resp.body) } end |
#slug ⇒ String
Returns The unique identifier for this module release.
33 34 35 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 33 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.
50 51 52 53 54 55 56 |
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 50 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 |