Module: Puppet::Network::FormatSupport

Overview

Provides network serialization support when included

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



8
9
10
# File 'lib/puppet/network/format_support.rb', line 8

def self.included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#mime(format = nil) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/puppet/network/format_support.rb', line 119

def mime(format = nil)
  format ||= self.class.default_format

  self.class.get_format(format).mime
rescue => err
  # TRANSLATORS "mime" is a function name and should not be translated
  raise Puppet::Network::FormatHandler::FormatError, _("Could not mime to %{format}: %{err}") % { format: format, err: err }, err.backtrace
end

#render(format = nil) ⇒ Object



110
111
112
113
114
115
116
117
# File 'lib/puppet/network/format_support.rb', line 110

def render(format = nil)
  format ||= self.class.default_format

  self.class.get_format(format).render(self)
rescue => err
  # TRANSLATORS "render" is a function name and should not be translated
  raise Puppet::Network::FormatHandler::FormatError, _("Could not render to %{format}: %{err}") % { format: format, err: err }, err.backtrace
end

#support_format?(name) ⇒ Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/puppet/network/format_support.rb', line 128

def support_format?(name)
  self.class.support_format?(name)
end

#to_data_hash(*args) ⇒ Hash

This method is abstract.

This method may be implemented to return a hash object that is used for serializing. The object returned by this method should contain all the info needed to instantiate it again. If the method exists it will be called from to_msgpack and other serialization methods.

Returns:

  • (Hash)


# File 'lib/puppet/network/format_support.rb', line 132

#to_json(*args) ⇒ Object



106
107
108
# File 'lib/puppet/network/format_support.rb', line 106

def to_json(*args)
  Puppet::Util::Json.dump(to_data_hash, *args)
end

#to_msgpack(*args) ⇒ Object



97
98
99
# File 'lib/puppet/network/format_support.rb', line 97

def to_msgpack(*args)
  to_data_hash.to_msgpack(*args)
end

#to_pson(*args) ⇒ Object

@deprecated, use to_json



102
103
104
# File 'lib/puppet/network/format_support.rb', line 102

def to_pson(*args)
  to_data_hash.to_pson(*args)
end