aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/mime_type.rb
blob: 0ab022100784447883ce0199f7a54c627d544a2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Mime
  class Type < String
    def initialize(string, part_of_all = true)
      @part_of_all = part_of_all
      super(string)
    end
    
    def to_sym
      SYMBOLIZED_MIME_TYPES[self] ? SYMBOLIZED_MIME_TYPES[self] : to_sym
    end

    def ===(list)
      if list.is_a?(Array)
        list.include?(self)
      else
        super
      end
    end
  end

  SYMBOLIZED_MIME_TYPES = {
    ""                         => :unspecified,
    "*/*"                      => :all,
    "text/html"                => :html,
    "application/javascript"   => :js,
    "application/x-javascript" => :js,
    "text/javascript"          => :js,
    "text/xml"                 => :xml,
    "application/xml"          => :xml,
    "application/rss+xml"      => :rss,
    "application/rss+atom"     => :atom,
    "application/x-xml"        => :xml,
    "application/x-yaml"       => :yaml
  }

  ALL        = Type.new "*/*"
  HTML       = Type.new "text/html"
  JS         = Type.new "text/javascript"
  JAVASCRIPT = Type.new "text/javascript"
  XML        = Type.new "application/xml"
  RSS        = Type.new "application/rss+xml"
  ATOM       = Type.new "application/rss+atom"
  YAML       = Type.new "application/x-yaml"
end