Class: Puppet::FileBucket::File Private

Inherits:
Object
  • Object
show all
Extended by:
Indirector
Defined in:
lib/puppet/file_bucket/file.rb

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.

Defined Under Namespace

Classes: FileContents, StringContents

Constant Summary

Constants included from Indirector

Indirector::BadNameRegexp

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Indirector

configure_routes, indirects

Constructor Details

#initialize(contents, options = {}) ⇒ File

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.

Returns a new instance of File.

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/puppet/file_bucket/file.rb', line 22

def initialize(contents, options = {})
  case contents
  when String
    @contents = StringContents.new(contents)
  when Pathname
    @contents = FileContents.new(contents)
  else
    raise ArgumentError, _("contents must be a String or Pathname, got a %{contents_class}") % { contents_class: contents.class }
  end

  @bucket_path = options.delete(:bucket_path)
  @checksum_type = Puppet[:digest_algorithm].to_sym
  raise ArgumentError, _("Unknown option(s): %{opts}") % { opts: options.keys.join(', ') } unless options.empty?
end

Instance Attribute Details

#bucket_pathObject (readonly)

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.



16
17
18
# File 'lib/puppet/file_bucket/file.rb', line 16

def bucket_path
  @bucket_path
end

Class Method Details

.from_binary(contents) ⇒ 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.



75
76
77
# File 'lib/puppet/file_bucket/file.rb', line 75

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

.supported_formatsObject

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.



18
19
20
# File 'lib/puppet/file_bucket/file.rb', line 18

def self.supported_formats
  [:binary]
end

Instance Method Details

#checksumObject

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.



51
52
53
# File 'lib/puppet/file_bucket/file.rb', line 51

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

#checksum_dataObject

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.



55
56
57
# File 'lib/puppet/file_bucket/file.rb', line 55

def checksum_data
  @checksum_data ||= @contents.checksum_data(@checksum_type)
end

#checksum_typeObject

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.



47
48
49
# File 'lib/puppet/file_bucket/file.rb', line 47

def checksum_type
  @checksum_type.to_s
end

#contentsObject

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.



67
68
69
# File 'lib/puppet/file_bucket/file.rb', line 67

def contents
  to_binary
end

#nameObject

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.



71
72
73
# File 'lib/puppet/file_bucket/file.rb', line 71

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

#sizeNum

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.

Returns The size of the contents.

Returns:

  • (Num)

    The size of the contents



38
39
40
# File 'lib/puppet/file_bucket/file.rb', line 38

def size
  @contents.size()
end

#stream(&block) ⇒ IO

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.

Returns A stream that reads the contents.

Returns:

  • (IO)

    A stream that reads the contents



43
44
45
# File 'lib/puppet/file_bucket/file.rb', line 43

def stream(&block)
  @contents.stream(&block)
end

#to_binaryObject

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.



63
64
65
# File 'lib/puppet/file_bucket/file.rb', line 63

def to_binary
  @contents.to_binary
end

#to_sObject

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.



59
60
61
# File 'lib/puppet/file_bucket/file.rb', line 59

def to_s
  to_binary
end