Sha256: c954f01442f7c6d8c57518717bef5191058f47f827bc7189af0b91d39011dafb

Contents?: true

Size: 1.22 KB

Versions: 41

Compression:

Stored size: 1.22 KB

Contents

require 'digest/md5'

module Puppet::ModuleTool

  # = Checksums
  #
  # This class proides methods for generating checksums for data and adding
  # them to +Metadata+.
  class Checksums
    include Enumerable

    # Instantiate object with string +path+ to create checksums from.
    def initialize(path)
      @path = Pathname.new(path)
    end

    # Return checksum for the +Pathname+.
    def checksum(pathname)
      return Digest::MD5.hexdigest(pathname.read)
    end

    # Return checksums for object's +Pathname+, generate if it's needed.
    # Result is a hash of path strings to checksum strings.
    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

    # TODO: Why?
    def each(&block)
      data.each(&block)
    end

    # Update +Metadata+'s checksums with this object's.
    def annotate(metadata)
      metadata.checksums.replace(data)
    end

    # TODO: Move the Checksummer#run checksum checking to here?

  end
end

Version data entries

41 entries across 41 versions & 3 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/module_tool/checksums.rb
puppet-parse-0.1.3 lib/vendor/puppet/module_tool/checksums.rb
puppet-parse-0.1.2 lib/vendor/puppet/module_tool/checksums.rb
puppet-parse-0.1.1 lib/vendor/puppet/module_tool/checksums.rb
puppet-2.7.26 lib/puppet/module_tool/checksums.rb
puppet-2.7.25 lib/puppet/module_tool/checksums.rb
puppet-2.7.24 lib/puppet/module_tool/checksums.rb
puppet-2.7.23 lib/puppet/module_tool/checksums.rb
puppet-2.7.22 lib/puppet/module_tool/checksums.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/lib/puppet/module_tool/checksums.rb
puppet-parse-0.1.0 lib/vendor/puppet/module_tool/checksums.rb
puppet-parse-0.0.6 lib/vendor/puppet/module_tool/checksums.rb
puppet-2.7.21 lib/puppet/module_tool/checksums.rb
puppet-3.1.1 lib/puppet/module_tool/checksums.rb
puppet-parse-0.0.5 lib/vendor/puppet/module_tool/checksums.rb
puppet-parse-0.0.4 lib/vendor/puppet/module_tool/checksums.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/lib/puppet/module_tool/checksums.rb
puppet-3.1.0 lib/puppet/module_tool/checksums.rb
puppet-3.1.0.rc2 lib/puppet/module_tool/checksums.rb
puppet-3.1.0.rc1 lib/puppet/module_tool/checksums.rb