Sha256: 0955e536c7f84ffc615a10eef29e99cffa2d4ca8e6d2abe8299a679d3c5d76c8
Contents?: true
Size: 1.9 KB
Versions: 4
Compression:
Stored size: 1.9 KB
Contents
# frozen_string_literal: true require "mime/types/deprecations" class << MIME::Types include Enumerable ## def new(*) # :nodoc: super.tap do |types| __instances__.add types end end # MIME::Types#[] against the default MIME::Types registry. def [](type_id, complete: false, registered: false) __types__[type_id, complete: complete, registered: registered] end # MIME::Types#count against the default MIME::Types registry. def count __types__.count end # MIME::Types#each against the default MIME::Types registry. def each if block_given? __types__.each { |t| yield t } else enum_for(:each) end end # MIME::Types#type_for against the default MIME::Types registry. def type_for(filename) __types__.type_for(filename) end alias_method :of, :type_for # MIME::Types#add against the default MIME::Types registry. def add(*types) __types__.add(*types) end private def lazy_load? return unless ENV.key?("RUBY_MIME_TYPES_LAZY_LOAD") deprecated( message: "Lazy loading ($RUBY_MIME_TYPES_LAZY_LOAD) is deprecated and will be removed." ) ENV["RUBY_MIME_TYPES_LAZY_LOAD"] != "false" end def __types__ (defined?(@__types__) && @__types__) || load_default_mime_types end unless private_method_defined?(:load_mode) def load_mode {columnar: true} end end def load_default_mime_types(mode = load_mode) if (@__types__ = MIME::Types::Cache.load) __instances__.add(@__types__) else @__types__ = MIME::Types::Loader.load(mode) MIME::Types::Cache.save(@__types__) end @__types__ end def __instances__ @__instances__ ||= Set.new end def reindex_extensions(type) __instances__.each do |instance| instance.send(:reindex_extensions!, type) end true end end ## class MIME::Types load_default_mime_types(load_mode) unless lazy_load? end
Version data entries
4 entries across 4 versions & 2 rubygems