Module: Puppet::Network::FormatSupport::ClassMethods

Defined in:
lib/puppet/network/format_support.rb

Instance Method Summary collapse

Instance Method Details

#convert_from(format, data) ⇒ Object



11
12
13
14
15
16
# File 'lib/puppet/network/format_support.rb', line 11

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

#convert_from_multiple(format, data) ⇒ Object



18
19
20
21
22
23
# File 'lib/puppet/network/format_support.rb', line 18

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

#default_formatObject



32
33
34
# File 'lib/puppet/network/format_support.rb', line 32

def default_format
  supported_formats[0]
end

#get_format(format_name) ⇒ 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.



58
59
60
# File 'lib/puppet/network/format_support.rb', line 58

def get_format(format_name)
  format_handler.format_for(format_name)
end

#render_multiple(format, instances) ⇒ Object



25
26
27
28
29
30
# File 'lib/puppet/network/format_support.rb', line 25

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

#support_format?(name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/puppet/network/format_support.rb', line 36

def support_format?(name)
  Puppet::Network::FormatHandler.format(name).supported?(self)
end

#supported_formatsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/puppet/network/format_support.rb', line 40

def supported_formats
  result = format_handler.formats.collect do |f|
    format_handler.format(f)
  end.find_all do |f|
    f.supported?(self)
  end.sort do |a, b|
    # It's an inverse sort -- higher weight formats go first.
    b.weight <=> a.weight
  end

  result = put_preferred_format_first(result).map(&:name)

  Puppet.debug "#{friendly_name} supports formats: #{result.join(' ')}"

  result
end