Module: Mime

Defined in:
lib/action_dispatch/http/mime_type.rb

Defined Under Namespace

Classes: AllType, Mimes, NullType, Type

Constant Summary collapse

SET =
Mimes.new
EXTENSION_LOOKUP =
{}
LOOKUP =
{}
ALL =

ALL isn’t a real MIME type, so we don’t register it for lookup with the other concrete types. It’s a wildcard match that we use for ‘respond_to` negotiation internals.

AllType.instance

Class Method Summary collapse

Class Method Details

.[](type) ⇒ Object



39
40
41
42
# File 'lib/action_dispatch/http/mime_type.rb', line 39

def [](type)
  return type if type.is_a?(Type)
  Type.lookup_by_extension(type)
end

.const_defined?(sym, inherit = true) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/action_dispatch/http/mime_type.rb', line 62

def const_defined?(sym, inherit = true)
  ext = sym.downcase
  if Mime[ext]
    ActiveSupport::Deprecation.warn(<<-MSG.squish)
      Accessing mime types via constants is deprecated.
      Please change `Mime.const_defined?(#{sym})` to `Mime[:#{ext}]`.
    MSG
    true
  else
    super
  end
end

.const_missing(sym) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/action_dispatch/http/mime_type.rb', line 49

def const_missing(sym)
  ext = sym.downcase
  if Mime[ext]
    ActiveSupport::Deprecation.warn(<<-MSG.squish)
      Accessing mime types via constants is deprecated.
      Please change `Mime::#{sym}` to `Mime[:#{ext}]`.
    MSG
    Mime[ext]
  else
    super
  end
end

.fetch(type) ⇒ Object



44
45
46
47
# File 'lib/action_dispatch/http/mime_type.rb', line 44

def fetch(type)
  return type if type.is_a?(Type)
  EXTENSION_LOOKUP.fetch(type.to_s) { |k| yield k }
end