Module: Puppet::Network::FormatHandler

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

Constant Summary

Class Method Summary (collapse)

Class Method Details

+ (Object) format_to_canonical_name_or_nil(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.



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

+ (Puppet::Network::Format?) most_suitable_format_for(accepted, supported)

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.

Parameters:

  • accepted (Array<String, Symbol>)

    the accepted formats in a form a that generally conforms to an HTTP Accept header. Any quality specifiers are ignored and instead the formats are simply in strict preference order (most preferred is first)

  • supported (Array<Symbol>)

    the names of the supported formats (the most preferred format is first)

Returns:

  • (Puppet::Network::Format, nil)

    the most suitable format



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