module Puppet::Network::FormatSupport::ClassMethods

Public Instance Methods

convert_from(format, data) click to toggle source
   # File lib/puppet/network/format_support.rb
12 def convert_from(format, data)
13   get_format(format).intern(self, data)
14 rescue => err
15   #TRANSLATORS "intern" is a function name and should not be translated
16   raise Puppet::Network::FormatHandler::FormatError, _("Could not intern from %{format}: %{err}") % { format: format, err: err }, err.backtrace
17 end
convert_from_multiple(format, data) click to toggle source
   # File lib/puppet/network/format_support.rb
19 def convert_from_multiple(format, data)
20   get_format(format).intern_multiple(self, data)
21 rescue => err
22   #TRANSLATORS "intern_multiple" is a function name and should not be translated
23   raise Puppet::Network::FormatHandler::FormatError, _("Could not intern_multiple from %{format}: %{err}") % { format: format, err: err }, err.backtrace
24 end
default_format() click to toggle source
   # File lib/puppet/network/format_support.rb
33 def default_format
34   supported_formats[0]
35 end
get_format(format_name) click to toggle source

@api private

   # File lib/puppet/network/format_support.rb
59 def get_format(format_name)
60   format_handler.format_for(format_name)
61 end
render_multiple(format, instances) click to toggle source
   # File lib/puppet/network/format_support.rb
26 def render_multiple(format, instances)
27   get_format(format).render_multiple(instances)
28 rescue => err
29   #TRANSLATORS "render_multiple" is a function name and should not be translated
30   raise Puppet::Network::FormatHandler::FormatError, _("Could not render_multiple to %{format}: %{err}") % { format: format, err: err }, err.backtrace
31 end
support_format?(name) click to toggle source
   # File lib/puppet/network/format_support.rb
37 def support_format?(name)
38   Puppet::Network::FormatHandler.format(name).supported?(self)
39 end
supported_formats() click to toggle source
   # File lib/puppet/network/format_support.rb
41 def supported_formats
42   result = format_handler.formats.collect do |f|
43     format_handler.format(f)
44   end.find_all do |f|
45     f.supported?(self)
46   end.sort do |a, b|
47     # It's an inverse sort -- higher weight formats go first.
48     b.weight <=> a.weight
49   end
50 
51   result = put_preferred_format_first(result).map(&:name)
52 
53   Puppet.debug { "#{friendly_name} supports formats: #{result.join(' ')}" }
54 
55   result
56 end

Private Instance Methods

format_handler() click to toggle source
   # File lib/puppet/network/format_support.rb
65 def format_handler
66   Puppet::Network::FormatHandler
67 end
friendly_name() click to toggle source
   # File lib/puppet/network/format_support.rb
69 def friendly_name
70   if self.respond_to? :indirection
71     indirection.name
72   else
73     self
74   end
75 end
put_preferred_format_first(list) click to toggle source
   # File lib/puppet/network/format_support.rb
77 def put_preferred_format_first(list)
78   preferred_format = Puppet.settings[:preferred_serialization_format].to_s
79 
80   preferred = list.select { |format|
81     format.mime.end_with?(preferred_format)
82   }
83 
84   if preferred.empty?
85     Puppet.debug { "Value of 'preferred_serialization_format' (#{preferred_format}) is invalid for #{friendly_name}, using default (#{list.first.name})" }
86   else
87     list = preferred + list.reject { |format|
88       format.mime.end_with?(preferred_format)
89     }
90   end
91 
92   list
93 end