Class: Puppet::ModuleTool::Checksums Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Network::FormatSupport
Defined in:
lib/puppet/module_tool/checksums.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Checksums

This class provides methods for generating checksums for data and adding them to Metadata.

Instance Method Summary collapse

Methods included from Network::FormatSupport

included, #mime, #render, #support_format?, #to_json, #to_msgpack, #to_pson

Constructor Details

#initialize(path) ⇒ Checksums

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Instantiate object with string path to create checksums from.


15
16
17
# File 'lib/puppet/module_tool/checksums.rb', line 15

def initialize(path)
  @path = Pathname.new(path)
end

Instance Method Details

#checksum(pathname) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return checksum for the Pathname.


20
21
22
# File 'lib/puppet/module_tool/checksums.rb', line 20

def checksum(pathname)
  return Digest::MD5.hexdigest(Puppet::FileSystem.binread(pathname))
end

#dataObject Also known as: to_data_hash, to_hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return checksums for object's Pathname, generate if it's needed. Result is a hash of path strings to checksum strings.


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/puppet/module_tool/checksums.rb', line 26

def data
  unless @data
    @data = {}
    @path.find do |descendant|
      if Puppet::ModuleTool.artifact?(descendant)
        Find.prune
      elsif descendant.file?
        path = descendant.relative_path_from(@path)
        @data[path.to_s] = checksum(descendant)
      end
    end
  end
  return @data
end

#each(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: Why?


45
46
47
# File 'lib/puppet/module_tool/checksums.rb', line 45

def each(&block)
  data.each(&block)
end