123456789_123456789_123456789_123456789_123456789_

Class: Mime::Type::AcceptList

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionpack/lib/action_dispatch/http/mime_type.rb

Class Method Summary

Class Method Details

.find_item_by_name(array, name)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/http/mime_type.rb', line 151

def self.find_item_by_name(array, name)
  array.index { |item| item.name == name }
end

.sort!(list)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/http/mime_type.rb', line 109

def self.sort!(list)
  list.sort!

  text_xml_idx = find_item_by_name list, "text/xml"
  app_xml_idx = find_item_by_name list, Mime[:xml].to_s

  # Take care of the broken text/xml entry by renaming or deleting it.
  if text_xml_idx && app_xml_idx
    app_xml = list[app_xml_idx]
    text_xml = list[text_xml_idx]

    app_xml.q = [text_xml.q, app_xml.q].max # Set the q value to the max of the two.
    if app_xml_idx > text_xml_idx  # Make sure app_xml is ahead of text_xml in the list.
      list[app_xml_idx], list[text_xml_idx] = text_xml, app_xml
      app_xml_idx, text_xml_idx = text_xml_idx, app_xml_idx
    end
    list.delete_at(text_xml_idx)  # Delete text_xml from the list.
  elsif text_xml_idx
    list[text_xml_idx].name = Mime[:xml].to_s
  end

  # Look for more specific XML-based types and sort them ahead of app/xml.
  if app_xml_idx
    app_xml = list[app_xml_idx]
    idx = app_xml_idx

    while idx < list.length
      type = list[idx]
      break if type.q < app_xml.q

      if type.name.end_with? "+xml"
        list[app_xml_idx], list[idx] = list[idx], app_xml
        app_xml_idx = idx
      end
      idx += 1
    end
  end

  list.map! { |i| Mime::Type.lookup(i.name) }.uniq!
  list
end