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.



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

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.



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

def checksum(pathname)
  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.



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

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
  @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?



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

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