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)


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

def initialize(contents, options = {})
  case contents
  when String
    @contents = StringContents.new(contents)
  when Pathname
    @contents = FileContents.new(contents)
  else
    raise ArgumentError.new(_("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.new(_("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.



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

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.



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

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



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

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.



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

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.



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

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.



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

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.



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

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.



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

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



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

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



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

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.



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

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.



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

def to_s
  to_binary
end