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



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

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



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

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



34
35
36
# File 'lib/puppet/network/format_support.rb', line 34

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.



60
61
62
# File 'lib/puppet/network/format_support.rb', line 60

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

#render_multiple(format, instances) ⇒ Object



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

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)


38
39
40
# File 'lib/puppet/network/format_support.rb', line 38

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

#supported_formatsObject



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

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