Class: Puppet::ModuleTool::Checksums
- Includes:
- Enumerable, Network::FormatSupport
- Defined in:
- lib/puppet/module_tool/checksums.rb
Overview
Checksums
This class provides methods for generating checksums for data and adding them to Metadata
.
Instance Method Summary collapse
-
#checksum(pathname) ⇒ Object
Return checksum for the
Pathname
. -
#data ⇒ Object
(also: #to_data_hash, #to_hash)
Return checksums for object’s
Pathname
, generate if it’s needed. -
#each(&block) ⇒ Object
TODO: Why?.
-
#initialize(path) ⇒ Checksums
constructor
Instantiate object with string
path
to create checksums from.
Methods included from Enumerable
Methods included from Network::FormatSupport
included, #mime, #render, #support_format?, #to_json, #to_msgpack, #to_pson
Constructor Details
#initialize(path) ⇒ Checksums
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
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 |
#data ⇒ Object Also known as: to_data_hash, to_hash
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
TODO: Why?
45 46 47 |
# File 'lib/puppet/module_tool/checksums.rb', line 45 def each(&block) data.each(&block) end |