Class: PuppetForge::V3::ModuleRelease

Inherits:
Object
  • Object
show all
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

Connection::USER_AGENT

Instance Attribute Summary collapse

Attributes included from Connection

#conn

Instance Method Summary collapse

Methods included from Connection

authorization, authorization=, #make_connection

Constructor Details

#initialize(full_name, version) ⇒ ModuleRelease

Returns a new instance of ModuleRelease.

Parameters:

  • full_name (String)

    The name of the module, will be normalized to a hyphen delimited name.

  • version (String)


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_nameObject (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

#versionObject (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

#dataHash

Returns The complete Forge resposne for this release.

Returns:

  • (Hash)

    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.

Parameters:

  • path (Pathname)


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

#slugString

Returns The unique identifier for this module release.

Returns:

  • (String)

    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.

Parameters:

  • path (Pathname)


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