Class: CloudInit::Userdata::Gzipped

Inherits:
CloudInit::Userdata show all
Defined in:
lib/cloudinit_userdata/formats/gzipped.rb

Overview

This class is really just a special formatter that wraps another formatter and delegates an un-gzipped version of the string to the underlying parser.

Constant Summary collapse

PREFIX =
"\x1F\x8B".b.freeze

Constants inherited from CloudInit::Userdata

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CloudInit::Userdata

mimetypes, parse, register_format, #valid?

Constructor Details

#initialize(raw) ⇒ Gzipped

Returns a new instance of Gzipped.



14
15
16
17
# File 'lib/cloudinit_userdata/formats/gzipped.rb', line 14

def initialize(raw)
  super
  self.formatter = CloudInit::Userdata.parse(self.raw)
end

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



12
13
14
# File 'lib/cloudinit_userdata/formats/gzipped.rb', line 12

def formatter
  @formatter
end

Class Method Details

.match?(value) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/cloudinit_userdata/formats/gzipped.rb', line 39

def self.match?(value)
  !value.nil? && value[0..1] == PREFIX
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/cloudinit_userdata/formats/gzipped.rb', line 27

def empty?
  formatter.empty?
end

#raw(decompressed = true) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/cloudinit_userdata/formats/gzipped.rb', line 19

def raw(decompressed = true)
  if decompressed
    Zlib::GzipReader.new(StringIO.new(super())).read
  else
    super()
  end
end

#to_sObject



35
36
37
# File 'lib/cloudinit_userdata/formats/gzipped.rb', line 35

def to_s
  raw(false)
end

#validateObject



31
32
33
# File 'lib/cloudinit_userdata/formats/gzipped.rb', line 31

def validate
  formatter.validate
end