Module: Puppet::Network::FormatHandler

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

Constant Summary

Class Method Summary collapse

Class Method Details

.format_to_canonical_name_or_nil(format) ⇒ 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.



98
99
100
101
102
# File 'lib/puppet/network/format_handler.rb', line 98

def self.format_to_canonical_name_or_nil(format)
  format_to_canonical_name(format)
rescue ArgumentError
  nil
end

.most_suitable_format_for(accepted, supported) ⇒ Puppet::Network::Format?

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.

Determine which of the accepted formats should be used given what is supported.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/puppet/network/format_handler.rb', line 79

def self.most_suitable_format_for(accepted, supported)
  format_name = accepted.collect do |accepted|
    accepted.to_s.sub(/;q=.*$/, '')
  end.collect do |accepted|
    if accepted == ALL_MEDIA_TYPES
      supported.first
    else
      format_to_canonical_name_or_nil(accepted)
    end
  end.find do |accepted|
    supported.include?(accepted)
  end

  if format_name
    format_for(format_name)
  end
end