Sha256: b2e93d6dda66c6d63683a6312b890532f5fc9af96fc4eb671cfec570f0a439a6

Contents?: true

Size: 1.31 KB

Versions: 47

Compression:

Stored size: 1.31 KB

Contents

require 'puppet/file_bucket'
require 'puppet/indirector'
require 'puppet/util/checksums'
require 'digest/md5'

class Puppet::FileBucket::File
  # This class handles the abstract notion of a file in a filebucket.
  # There are mechanisms to save and load this file locally and remotely in puppet/indirector/filebucketfile/*
  # There is a compatibility class that emulates pre-indirector filebuckets in Puppet::FileBucket::Dipper
  extend Puppet::Indirector
  indirects :file_bucket_file, :terminus_class => :selector

  attr :contents
  attr :bucket_path

  def initialize(contents, options = {})
    raise ArgumentError.new("contents must be a String, got a #{contents.class}") unless contents.is_a?(String)
    @contents = contents

    @bucket_path = options.delete(:bucket_path)
    raise ArgumentError.new("Unknown option(s): #{options.keys.join(', ')}") unless options.empty?
  end

  def checksum_type
    'md5'
  end

  def checksum
    "{#{checksum_type}}#{checksum_data}"
  end

  def checksum_data
    @checksum_data ||= Digest::MD5.hexdigest(contents)
  end

  def to_s
    contents
  end

  def name
    "#{checksum_type}/#{checksum_data}"
  end

  def self.from_s(contents)
    self.new(contents)
  end

  def to_pson
    { "contents" => contents }.to_pson
  end

  def self.from_pson(pson)
    self.new(pson["contents"])
  end
end

Version data entries

47 entries across 47 versions & 3 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/file_bucket/file.rb
puppet-parse-0.1.3 lib/vendor/puppet/file_bucket/file.rb
puppet-parse-0.1.2 lib/vendor/puppet/file_bucket/file.rb
puppet-parse-0.1.1 lib/vendor/puppet/file_bucket/file.rb
puppet-2.7.26 lib/puppet/file_bucket/file.rb
puppet-2.7.25 lib/puppet/file_bucket/file.rb
puppet-2.7.24 lib/puppet/file_bucket/file.rb
puppet-3.3.0.rc2 lib/puppet/file_bucket/file.rb
puppet-3.2.4 lib/puppet/file_bucket/file.rb
puppet-2.7.23 lib/puppet/file_bucket/file.rb
puppet-3.2.3 lib/puppet/file_bucket/file.rb
puppet-3.2.3.rc1 lib/puppet/file_bucket/file.rb
puppet-3.2.2 lib/puppet/file_bucket/file.rb
puppet-2.7.22 lib/puppet/file_bucket/file.rb
puppet-3.2.1 lib/puppet/file_bucket/file.rb
puppet-3.2.1.rc1 lib/puppet/file_bucket/file.rb
puppet-3.2.0.rc2 lib/puppet/file_bucket/file.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/lib/puppet/file_bucket/file.rb
puppet-3.2.0.rc1 lib/puppet/file_bucket/file.rb
puppet-parse-0.1.0 lib/vendor/puppet/file_bucket/file.rb