module Puppet::Network::FormatSupport::ClassMethods
Public Instance Methods
convert_from(format, data)
click to toggle source
# File lib/puppet/network/format_support.rb 11 def convert_from(format, data) 12 get_format(format).intern(self, data) 13 rescue => err 14 #TRANSLATORS "intern" is a function name and should not be translated 15 raise Puppet::Network::FormatHandler::FormatError, _("Could not intern from %{format}: %{err}") % { format: format, err: err }, err.backtrace 16 end
convert_from_multiple(format, data)
click to toggle source
# File lib/puppet/network/format_support.rb 18 def convert_from_multiple(format, data) 19 get_format(format).intern_multiple(self, data) 20 rescue => err 21 #TRANSLATORS "intern_multiple" is a function name and should not be translated 22 raise Puppet::Network::FormatHandler::FormatError, _("Could not intern_multiple from %{format}: %{err}") % { format: format, err: err }, err.backtrace 23 end
default_format()
click to toggle source
# File lib/puppet/network/format_support.rb 32 def default_format 33 supported_formats[0] 34 end
get_format(format_name)
click to toggle source
@api private
# File lib/puppet/network/format_support.rb 58 def get_format(format_name) 59 format_handler.format_for(format_name) 60 end
render_multiple(format, instances)
click to toggle source
# File lib/puppet/network/format_support.rb 25 def render_multiple(format, instances) 26 get_format(format).render_multiple(instances) 27 rescue => err 28 #TRANSLATORS "render_multiple" is a function name and should not be translated 29 raise Puppet::Network::FormatHandler::FormatError, _("Could not render_multiple to %{format}: %{err}") % { format: format, err: err }, err.backtrace 30 end
support_format?(name)
click to toggle source
# File lib/puppet/network/format_support.rb 36 def support_format?(name) 37 Puppet::Network::FormatHandler.format(name).supported?(self) 38 end
supported_formats()
click to toggle source
# File lib/puppet/network/format_support.rb 40 def supported_formats 41 result = format_handler.formats.collect do |f| 42 format_handler.format(f) 43 end.find_all do |f| 44 f.supported?(self) 45 end.sort do |a, b| 46 # It's an inverse sort -- higher weight formats go first. 47 b.weight <=> a.weight 48 end 49 50 result = put_preferred_format_first(result).map(&:name) 51 52 Puppet.debug { "#{friendly_name} supports formats: #{result.join(' ')}" } 53 54 result 55 end
Private Instance Methods
format_handler()
click to toggle source
# File lib/puppet/network/format_support.rb 64 def format_handler 65 Puppet::Network::FormatHandler 66 end
friendly_name()
click to toggle source
# File lib/puppet/network/format_support.rb 68 def friendly_name 69 if self.respond_to? :indirection 70 indirection.name 71 else 72 self 73 end 74 end
put_preferred_format_first(list)
click to toggle source
# File lib/puppet/network/format_support.rb 76 def put_preferred_format_first(list) 77 preferred_format = Puppet.settings[:preferred_serialization_format].to_s 78 79 preferred = list.select { |format| 80 format.mime.end_with?(preferred_format) 81 } 82 83 if preferred.empty? 84 Puppet.debug { "Value of 'preferred_serialization_format' (#{preferred_format}) is invalid for #{friendly_name}, using default (#{list.first.name})" } 85 else 86 list = preferred + list.reject { |format| 87 format.mime.end_with?(preferred_format) 88 } 89 end 90 91 list 92 end