mime-types 2.99.3 → 3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{Code-of-Conduct.rdoc → Code-of-Conduct.md} +19 -20
- data/Contributing.md +139 -0
- data/History.md +208 -0
- data/{Licence.rdoc → Licence.md} +4 -18
- data/Manifest.txt +8 -25
- data/README.rdoc +63 -67
- data/Rakefile +144 -55
- data/lib/mime/type/columnar.rb +29 -62
- data/lib/mime/type.rb +192 -417
- data/lib/mime/types/_columnar.rb +137 -0
- data/lib/mime/types/cache.rb +51 -73
- data/lib/mime/types/columnar.rb +2 -147
- data/lib/mime/types/container.rb +94 -0
- data/lib/mime/types/deprecations.rb +5 -24
- data/lib/mime/types/full.rb +19 -0
- data/lib/mime/types/loader.rb +12 -141
- data/lib/mime/types/logger.rb +4 -0
- data/lib/mime/types/registry.rb +90 -0
- data/lib/mime/types.rb +43 -139
- data/lib/mime-types.rb +1 -1
- data/test/minitest_helper.rb +6 -12
- data/test/test_mime_type.rb +473 -455
- data/test/test_mime_types.rb +136 -86
- data/test/test_mime_types_cache.rb +83 -53
- data/test/test_mime_types_class.rb +119 -97
- data/test/test_mime_types_lazy.rb +27 -23
- data/test/test_mime_types_loader.rb +7 -32
- metadata +102 -62
- data/Contributing.rdoc +0 -170
- data/History-Types.rdoc +0 -454
- data/History.rdoc +0 -590
- data/data/mime-types.json +0 -1
- data/data/mime.content_type.column +0 -1980
- data/data/mime.docs.column +0 -1980
- data/data/mime.encoding.column +0 -1980
- data/data/mime.friendly.column +0 -1980
- data/data/mime.obsolete.column +0 -1980
- data/data/mime.registered.column +0 -1980
- data/data/mime.signature.column +0 -1980
- data/data/mime.use_instead.column +0 -1980
- data/data/mime.xrefs.column +0 -1980
- data/docs/COPYING.txt +0 -339
- data/docs/artistic.txt +0 -127
- data/lib/mime/types/loader_path.rb +0 -15
- data/support/apache_mime_types.rb +0 -108
- data/support/benchmarks/load.rb +0 -64
- data/support/benchmarks/load_allocations.rb +0 -83
- data/support/benchmarks/object_counts.rb +0 -41
- data/support/convert/columnar.rb +0 -88
- data/support/convert.rb +0 -158
- data/support/iana_registry.rb +0 -172
data/lib/mime/types/loader.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -*- ruby encoding: utf-8 -*-
|
2
4
|
|
5
|
+
##
|
3
6
|
module MIME; end
|
7
|
+
##
|
4
8
|
class MIME::Types; end
|
5
9
|
|
6
|
-
require 'mime/types/
|
10
|
+
require 'mime/types/data'
|
7
11
|
|
8
12
|
# This class is responsible for initializing the MIME::Types registry from
|
9
13
|
# the data files supplied with the mime-types library.
|
@@ -11,7 +15,7 @@ require 'mime/types/loader_path'
|
|
11
15
|
# The Loader will use one of the following paths:
|
12
16
|
# 1. The +path+ provided in its constructor argument;
|
13
17
|
# 2. The value of ENV['RUBY_MIME_TYPES_DATA']; or
|
14
|
-
# 3. The value of MIME::Types::
|
18
|
+
# 3. The value of MIME::Types::Data::PATH.
|
15
19
|
#
|
16
20
|
# When #load is called, the +path+ will be searched recursively for all YAML
|
17
21
|
# (.yml or .yaml) files. By convention, there is one file for each media
|
@@ -24,15 +28,11 @@ class MIME::Types::Loader
|
|
24
28
|
attr_reader :container
|
25
29
|
|
26
30
|
# Creates a Loader object that can be used to load MIME::Types registries
|
27
|
-
# into memory, using YAML, JSON, or
|
31
|
+
# into memory, using YAML, JSON, or Columnar registry format loaders.
|
28
32
|
def initialize(path = nil, container = nil)
|
29
|
-
path = path || ENV['RUBY_MIME_TYPES_DATA'] || MIME::Types::
|
33
|
+
path = path || ENV['RUBY_MIME_TYPES_DATA'] || MIME::Types::Data::PATH
|
30
34
|
@container = container || MIME::Types.new
|
31
35
|
@path = File.expand_path(path)
|
32
|
-
# begin
|
33
|
-
# require 'mime/lazy_types'
|
34
|
-
# @container.extend(MIME::LazyTypes)
|
35
|
-
# end
|
36
36
|
end
|
37
37
|
|
38
38
|
# Loads a MIME::Types registry from YAML files (<tt>*.yml</tt> or
|
@@ -41,8 +41,7 @@ class MIME::Types::Loader
|
|
41
41
|
# It is expected that the YAML objects contained within the registry array
|
42
42
|
# will be tagged as <tt>!ruby/object:MIME::Type</tt>.
|
43
43
|
#
|
44
|
-
# Note that the YAML format is about 2½ times *slower* than
|
45
|
-
# format or the JSON format.
|
44
|
+
# Note that the YAML format is about 2½ times *slower* than the JSON format.
|
46
45
|
#
|
47
46
|
# NOTE: The purpose of this format is purely for maintenance reasons.
|
48
47
|
def load_yaml
|
@@ -89,122 +88,19 @@ class MIME::Types::Loader
|
|
89
88
|
end
|
90
89
|
end
|
91
90
|
|
92
|
-
# Loads a MIME::Types registry from files found in +path+ that are in the
|
93
|
-
# v1 data format. The file search for this will exclude both JSON
|
94
|
-
# (<tt>*.json</tt>) and YAML (<tt>*.yml</tt> or <tt>*.yaml</tt>) files.
|
95
|
-
#
|
96
|
-
# This method has been deprecated and will be removed from mime-types 3.0.
|
97
|
-
def load_v1
|
98
|
-
MIME::Types.deprecated(self.class, __method__)
|
99
|
-
Dir[v1_path].sort.each do |f|
|
100
|
-
next if f =~ /\.(?:ya?ml|json|column)$/
|
101
|
-
container.add(self.class.load_from_v1(f, true), true)
|
102
|
-
end
|
103
|
-
container
|
104
|
-
end
|
105
|
-
|
106
|
-
# Raised when a V1 format file is discovered. This exception will be removed
|
107
|
-
# for mime-types 3.0.
|
108
|
-
BadV1Format = Class.new(Exception)
|
109
|
-
|
110
91
|
class << self
|
111
92
|
# Loads the default MIME::Type registry.
|
112
93
|
def load(options = { columnar: false })
|
113
94
|
new.load(options)
|
114
95
|
end
|
115
96
|
|
116
|
-
# Build the type list from a file in the format:
|
117
|
-
#
|
118
|
-
# [*][!][os:]mt/st[<ws>@ext][<ws>:enc][<ws>'url-list][<ws>=docs]
|
119
|
-
#
|
120
|
-
# == *
|
121
|
-
# An unofficial MIME type. This should be used if and only if the MIME type
|
122
|
-
# is not properly specified (that is, not under either x-type or
|
123
|
-
# vnd.name.type).
|
124
|
-
#
|
125
|
-
# == !
|
126
|
-
# An obsolete MIME type. May be used with an unofficial MIME type.
|
127
|
-
#
|
128
|
-
# == os:
|
129
|
-
# Platform-specific MIME type definition.
|
130
|
-
#
|
131
|
-
# == mt
|
132
|
-
# The media type.
|
133
|
-
#
|
134
|
-
# == st
|
135
|
-
# The media subtype.
|
136
|
-
#
|
137
|
-
# == <ws>@ext
|
138
|
-
# The list of comma-separated extensions.
|
139
|
-
#
|
140
|
-
# == <ws>:enc
|
141
|
-
# The encoding.
|
142
|
-
#
|
143
|
-
# == <ws>'url-list
|
144
|
-
# The list of comma-separated URLs.
|
145
|
-
#
|
146
|
-
# == <ws>=docs
|
147
|
-
# The documentation string.
|
148
|
-
#
|
149
|
-
# That is, everything except the media type and the subtype is optional. The
|
150
|
-
# more information that's available, though, the richer the values that can
|
151
|
-
# be provided.
|
152
|
-
#
|
153
|
-
# This method has been deprecated and will be removed in mime-types 3.0.
|
154
|
-
def load_from_v1(filename, __internal__ = false)
|
155
|
-
MIME::Types.deprecated(self.class, __method__) unless __internal__
|
156
|
-
data = read_file(filename).split($/)
|
157
|
-
mime = MIME::Types.new
|
158
|
-
data.each_with_index { |line, index|
|
159
|
-
item = line.chomp.strip
|
160
|
-
next if item.empty?
|
161
|
-
|
162
|
-
m = V1_FORMAT.match(item)
|
163
|
-
|
164
|
-
unless m
|
165
|
-
MIME::Types.logger.warn <<-EOS
|
166
|
-
#{filename}:#{index + 1}: Parsing error in v1 MIME type definition.
|
167
|
-
=> #{line}
|
168
|
-
EOS
|
169
|
-
fail BadV1Format, line
|
170
|
-
end
|
171
|
-
|
172
|
-
unregistered, obsolete, _, mediatype, subtype, extensions, encoding,
|
173
|
-
urls, docs, _ = *m.captures
|
174
|
-
|
175
|
-
next if mediatype.nil?
|
176
|
-
|
177
|
-
extensions &&= extensions.split(/,/)
|
178
|
-
urls &&= urls.split(/,/)
|
179
|
-
|
180
|
-
if docs.nil?
|
181
|
-
use_instead = nil
|
182
|
-
else
|
183
|
-
use_instead = docs.scan(%r{use-instead:(\S+)}).flatten.first
|
184
|
-
docs = docs.gsub(%r{use-instead:\S+}, '').squeeze(' \t')
|
185
|
-
end
|
186
|
-
|
187
|
-
mime_type = MIME::Type.new("#{mediatype}/#{subtype}") do |t|
|
188
|
-
t.extensions = extensions
|
189
|
-
t.encoding = encoding
|
190
|
-
t.obsolete = obsolete
|
191
|
-
t.registered = false if unregistered
|
192
|
-
t.use_instead = use_instead
|
193
|
-
t.docs = docs
|
194
|
-
end
|
195
|
-
|
196
|
-
mime.add_type(mime_type, true)
|
197
|
-
}
|
198
|
-
mime
|
199
|
-
end
|
200
|
-
|
201
97
|
# Loads MIME::Types from a single YAML file.
|
202
98
|
#
|
203
99
|
# It is expected that the YAML objects contained within the registry
|
204
100
|
# array will be tagged as <tt>!ruby/object:MIME::Type</tt>.
|
205
101
|
#
|
206
|
-
# Note that the YAML format is about 2½ times *slower* than
|
207
|
-
# format
|
102
|
+
# Note that the YAML format is about 2½ times *slower* than the JSON
|
103
|
+
# format.
|
208
104
|
#
|
209
105
|
# NOTE: The purpose of this format is purely for maintenance reasons.
|
210
106
|
def load_from_yaml(filename)
|
@@ -230,7 +126,7 @@ class MIME::Types::Loader
|
|
230
126
|
private
|
231
127
|
|
232
128
|
def read_file(filename)
|
233
|
-
File.open(filename, 'r:UTF-8:-'
|
129
|
+
File.open(filename, 'r:UTF-8:-', &:read)
|
234
130
|
end
|
235
131
|
end
|
236
132
|
|
@@ -247,29 +143,4 @@ class MIME::Types::Loader
|
|
247
143
|
def columnar_path
|
248
144
|
File.join(path, '*.column')
|
249
145
|
end
|
250
|
-
|
251
|
-
def v1_path
|
252
|
-
File.join(path, '*')
|
253
|
-
end
|
254
|
-
|
255
|
-
# The regular expression used to match a v1-format file-based MIME type
|
256
|
-
# definition.
|
257
|
-
#
|
258
|
-
# This constant has been deprecated and will be removed in mime-types 3.0.
|
259
|
-
V1_FORMAT = # :nodoc:
|
260
|
-
%r{\A\s*
|
261
|
-
([*])? # 0: Unregistered?
|
262
|
-
(!)? # 1: Obsolete?
|
263
|
-
(?:(\w+):)? # 2: Platform marker
|
264
|
-
([-\w.+]+)/([-\w.+]*) # 3, 4: Media Type
|
265
|
-
(?:\s+@(\S+))? # 5: Extensions
|
266
|
-
(?:\s+:(base64|7bit|8bit|quoted\-printable))? # 6: Encoding
|
267
|
-
(?:\s+'(\S+))? # 7: URL list
|
268
|
-
(?:\s+=(.+))? # 8: Documentation
|
269
|
-
(?:\s*([#].*)?)? # Comments
|
270
|
-
\s*
|
271
|
-
\z
|
272
|
-
}x
|
273
|
-
|
274
|
-
private_constant :V1_FORMAT if respond_to? :private_constant
|
275
146
|
end
|
data/lib/mime/types/logger.rb
CHANGED
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class << MIME::Types
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
##
|
7
|
+
def new(*) # :nodoc:
|
8
|
+
super.tap do |types|
|
9
|
+
__instances__.add types
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# MIME::Types#[] against the default MIME::Types registry.
|
14
|
+
def [](type_id, complete: false, registered: false)
|
15
|
+
__types__[type_id, complete: complete, registered: registered]
|
16
|
+
end
|
17
|
+
|
18
|
+
# MIME::Types#count against the default MIME::Types registry.
|
19
|
+
def count
|
20
|
+
__types__.count
|
21
|
+
end
|
22
|
+
|
23
|
+
# MIME::Types#each against the default MIME::Types registry.
|
24
|
+
def each
|
25
|
+
if block_given?
|
26
|
+
__types__.each { |t| yield t }
|
27
|
+
else
|
28
|
+
enum_for(:each)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# MIME::Types#type_for against the default MIME::Types registry.
|
33
|
+
def type_for(filename)
|
34
|
+
__types__.type_for(filename)
|
35
|
+
end
|
36
|
+
alias_method :of, :type_for
|
37
|
+
|
38
|
+
# MIME::Types#add against the default MIME::Types registry.
|
39
|
+
def add(*types)
|
40
|
+
__types__.add(*types)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def lazy_load?
|
46
|
+
if ENV.key?('RUBY_MIME_TYPES_LAZY_LOAD')
|
47
|
+
MIME::Types.logger.warn <<-WARNING.chomp
|
48
|
+
Lazy loading ($RUBY_MIME_TYPES_LAZY_LOAD) is deprecated and will be removed.
|
49
|
+
WARNING
|
50
|
+
|
51
|
+
(lazy = ENV['RUBY_MIME_TYPES_LAZY_LOAD']) && (lazy != 'false')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def __types__
|
56
|
+
(defined?(@__types__) and @__types__) or load_default_mime_types
|
57
|
+
end
|
58
|
+
|
59
|
+
unless private_method_defined?(:load_mode)
|
60
|
+
def load_mode
|
61
|
+
{ columnar: true }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def load_default_mime_types(mode = load_mode)
|
66
|
+
if @__types__ = MIME::Types::Cache.load
|
67
|
+
__instances__.add(@__types__)
|
68
|
+
else
|
69
|
+
@__types__ = MIME::Types::Loader.load(mode)
|
70
|
+
MIME::Types::Cache.save(@__types__)
|
71
|
+
end
|
72
|
+
@__types__
|
73
|
+
end
|
74
|
+
|
75
|
+
def __instances__
|
76
|
+
@__instances__ ||= Set.new
|
77
|
+
end
|
78
|
+
|
79
|
+
def reindex_extensions(type)
|
80
|
+
__instances__.each do |instance|
|
81
|
+
instance.send(:reindex_extensions!, type)
|
82
|
+
end
|
83
|
+
true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
class MIME::Types
|
89
|
+
load_default_mime_types(load_mode) unless lazy_load?
|
90
|
+
end
|
data/lib/mime/types.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
module MIME
|
5
|
+
##
|
6
|
+
class Types
|
7
|
+
end
|
8
|
+
end
|
2
9
|
|
3
|
-
require 'mime/types/deprecations'
|
4
10
|
require 'mime/type'
|
5
|
-
require 'mime/types/cache'
|
6
|
-
require 'mime/types/loader'
|
7
11
|
|
8
12
|
# MIME::Types is a registry of MIME types. It is both a class (created with
|
9
13
|
# MIME::Types.new) and a default registry (loaded automatically or through
|
@@ -66,37 +70,19 @@ class MIME::Types
|
|
66
70
|
|
67
71
|
include Enumerable
|
68
72
|
|
69
|
-
# The data version.
|
70
|
-
attr_reader :data_version
|
71
|
-
|
72
73
|
# Creates a new MIME::Types registry.
|
73
74
|
def initialize
|
74
75
|
@type_variants = Container.new
|
75
76
|
@extension_index = Container.new
|
76
|
-
@data_version = VERSION.dup.freeze
|
77
|
-
end
|
78
|
-
|
79
|
-
# This method is deprecated and will be removed in mime-types 3.0.
|
80
|
-
def add_type_variant(mime_type) # :nodoc:
|
81
|
-
MIME::Types.deprecated(self, __method__, :private)
|
82
|
-
add_type_variant!(mime_type)
|
83
|
-
end
|
84
|
-
|
85
|
-
# This method is deprecated and will be removed in mime-types 3.0.
|
86
|
-
def index_extensions(mime_type) # :nodoc:
|
87
|
-
MIME::Types.deprecated(self, __method__, :private)
|
88
|
-
index_extensions!(mime_type)
|
89
|
-
end
|
90
|
-
|
91
|
-
# This method is deprecated and will be removed in mime-types 3.0.
|
92
|
-
def defined_types # :nodoc:
|
93
|
-
MIME::Types.deprecated(self, __method__)
|
94
|
-
@type_variants.values.flatten
|
95
77
|
end
|
96
78
|
|
97
79
|
# Returns the number of known type variants.
|
98
80
|
def count
|
99
|
-
@type_variants.values.
|
81
|
+
@type_variants.values.inject(0) { |a, e| a + e.size }
|
82
|
+
end
|
83
|
+
|
84
|
+
def inspect # :nodoc:
|
85
|
+
"#<#{self.class}: #{count} variants, #{@extension_index.count} extensions>"
|
100
86
|
end
|
101
87
|
|
102
88
|
# Iterates through the type variants.
|
@@ -108,7 +94,7 @@ class MIME::Types
|
|
108
94
|
end
|
109
95
|
end
|
110
96
|
|
111
|
-
@__types__
|
97
|
+
@__types__ = nil
|
112
98
|
|
113
99
|
# Returns a list of MIME::Type objects, which may be empty. The optional
|
114
100
|
# flag parameters are <tt>:complete</tt> (finds only complete MIME::Type
|
@@ -135,13 +121,7 @@ class MIME::Types
|
|
135
121
|
# without;
|
136
122
|
# 5. Obsolete definitions use-instead clauses are compared.
|
137
123
|
# 6. Sort on name.
|
138
|
-
|
139
|
-
# The previously supported (but deprecated) <tt>:platform</tt> flag is now ignored.
|
140
|
-
def [](type_id, flags = {})
|
141
|
-
if flags.key?(:platform)
|
142
|
-
MIME::Types.deprecated(self, __method__, 'using the :platform flag')
|
143
|
-
end
|
144
|
-
|
124
|
+
def [](type_id, complete: false, registered: false)
|
145
125
|
matches = case type_id
|
146
126
|
when MIME::Type
|
147
127
|
@type_variants[type_id.simplified]
|
@@ -151,7 +131,9 @@ class MIME::Types
|
|
151
131
|
@type_variants[MIME::Type.simplified(type_id)]
|
152
132
|
end
|
153
133
|
|
154
|
-
prune_matches(matches,
|
134
|
+
prune_matches(matches, complete, registered).sort { |a, b|
|
135
|
+
a.priority_compare(b)
|
136
|
+
}
|
155
137
|
end
|
156
138
|
|
157
139
|
# Return the list of MIME::Types which belongs to the file based on its
|
@@ -166,17 +148,12 @@ class MIME::Types
|
|
166
148
|
# => [image/gif]
|
167
149
|
# puts MIME::Types.type_for(%w(citydesk.xml citydesk.gif))
|
168
150
|
# => [application/xml, image/gif, text/xml]
|
169
|
-
|
170
|
-
|
171
|
-
def type_for(filename, platform = :deprecated)
|
172
|
-
types = Array(filename).flat_map { |fn|
|
151
|
+
def type_for(filename)
|
152
|
+
Array(filename).flat_map { |fn|
|
173
153
|
@extension_index[fn.chomp.downcase[/\.?([^.]*?)$/, 1]]
|
174
|
-
}.compact.sort { |a, b|
|
175
|
-
|
176
|
-
|
177
|
-
MIME::Types.deprecated(self, __method__, 'using the platform parameter')
|
178
|
-
end
|
179
|
-
types
|
154
|
+
}.compact.inject(Set.new, :+).sort { |a, b|
|
155
|
+
a.priority_compare(b)
|
156
|
+
}
|
180
157
|
end
|
181
158
|
alias_method :of, :type_for
|
182
159
|
|
@@ -194,7 +171,7 @@ class MIME::Types
|
|
194
171
|
nil
|
195
172
|
when MIME::Types
|
196
173
|
variants = mime_type.instance_variable_get(:@type_variants)
|
197
|
-
add(*variants.values.
|
174
|
+
add(*variants.values.inject(Set.new, :+).to_a, quiet)
|
198
175
|
when Array
|
199
176
|
add(*mime_type, quiet)
|
200
177
|
else
|
@@ -217,110 +194,37 @@ Type #{type} is already registered as a variant of #{type.simplified}.
|
|
217
194
|
index_extensions!(type)
|
218
195
|
end
|
219
196
|
|
220
|
-
class << self
|
221
|
-
include Enumerable
|
222
|
-
|
223
|
-
# Load MIME::Types from a v1 file registry.
|
224
|
-
#
|
225
|
-
# This method has been deprecated and will be removed in mime-types 3.0.
|
226
|
-
def load_from_file(filename)
|
227
|
-
MIME::Types.deprecated(self, __method__)
|
228
|
-
MIME::Types::Loader.load_from_v1(filename)
|
229
|
-
end
|
230
|
-
|
231
|
-
# MIME::Types#[] against the default MIME::Types registry.
|
232
|
-
def [](type_id, flags = {})
|
233
|
-
__types__[type_id, flags]
|
234
|
-
end
|
235
|
-
|
236
|
-
# MIME::Types#count against the default MIME::Types registry.
|
237
|
-
def count
|
238
|
-
__types__.count
|
239
|
-
end
|
240
|
-
|
241
|
-
# MIME::Types#each against the default MIME::Types registry.
|
242
|
-
def each
|
243
|
-
if block_given?
|
244
|
-
__types__.each { |t| yield t }
|
245
|
-
else
|
246
|
-
enum_for(:each)
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
# MIME::Types#type_for against the default MIME::Types registry.
|
251
|
-
def type_for(filename, platform = :deprecated)
|
252
|
-
__types__.type_for(filename, platform)
|
253
|
-
end
|
254
|
-
alias_method :of, :type_for
|
255
|
-
|
256
|
-
# MIME::Types#add against the default MIME::Types registry.
|
257
|
-
def add(*types)
|
258
|
-
__types__.add(*types)
|
259
|
-
end
|
260
|
-
|
261
|
-
# Returns the currently defined cache file, if any.
|
262
|
-
#
|
263
|
-
# This method has been deprecated and will be removed in mime-types 3.0.
|
264
|
-
def cache_file
|
265
|
-
MIME::Types.deprecated(self, __method__)
|
266
|
-
ENV['RUBY_MIME_TYPES_CACHE']
|
267
|
-
end
|
268
|
-
|
269
|
-
def add_type_variant(mime_type) # :nodoc:
|
270
|
-
__types__.add_type_variant(mime_type)
|
271
|
-
end
|
272
|
-
|
273
|
-
def index_extensions(mime_type) # :nodoc:
|
274
|
-
__types__.index_extensions(mime_type)
|
275
|
-
end
|
276
|
-
|
277
|
-
private
|
278
|
-
|
279
|
-
def lazy_load?
|
280
|
-
(lazy = ENV['RUBY_MIME_TYPES_LAZY_LOAD']) && (lazy != 'false')
|
281
|
-
end
|
282
|
-
|
283
|
-
def __types__
|
284
|
-
(defined?(@__types__) and @__types__) or load_default_mime_types
|
285
|
-
end
|
286
|
-
|
287
|
-
unless private_method_defined?(:load_mode)
|
288
|
-
def load_mode
|
289
|
-
{}
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
def load_default_mime_types(mode = load_mode())
|
294
|
-
@__types__ = MIME::Types::Cache.load
|
295
|
-
unless @__types__
|
296
|
-
@__types__ = MIME::Types::Loader.load(mode)
|
297
|
-
MIME::Types::Cache.save(@__types__)
|
298
|
-
end
|
299
|
-
@__types__
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
197
|
private
|
304
198
|
|
305
199
|
def add_type_variant!(mime_type)
|
306
|
-
@type_variants
|
200
|
+
@type_variants.add(mime_type.simplified, mime_type)
|
201
|
+
end
|
202
|
+
|
203
|
+
def reindex_extensions!(mime_type)
|
204
|
+
return unless @type_variants[mime_type.simplified].include?(mime_type)
|
205
|
+
index_extensions!(mime_type)
|
307
206
|
end
|
308
207
|
|
309
208
|
def index_extensions!(mime_type)
|
310
|
-
mime_type.extensions.each { |ext| @extension_index
|
209
|
+
mime_type.extensions.each { |ext| @extension_index.add(ext, mime_type) }
|
311
210
|
end
|
312
211
|
|
313
|
-
def prune_matches(matches,
|
314
|
-
matches.delete_if { |e| !e.complete? } if
|
315
|
-
matches.delete_if { |e| !e.registered? } if
|
212
|
+
def prune_matches(matches, complete, registered)
|
213
|
+
matches.delete_if { |e| !e.complete? } if complete
|
214
|
+
matches.delete_if { |e| !e.registered? } if registered
|
316
215
|
matches
|
317
216
|
end
|
318
217
|
|
319
218
|
def match(pattern)
|
320
|
-
@type_variants.select { |k, _|
|
219
|
+
@type_variants.select { |k, _|
|
220
|
+
k =~ pattern
|
221
|
+
}.values.inject(Set.new, :+)
|
321
222
|
end
|
322
|
-
|
323
|
-
load_default_mime_types(load_mode) unless lazy_load?
|
324
223
|
end
|
325
224
|
|
326
|
-
|
225
|
+
require 'mime/types/cache'
|
226
|
+
require 'mime/types/container'
|
227
|
+
require 'mime/types/loader'
|
228
|
+
require 'mime/types/logger'
|
229
|
+
require 'mime/types/_columnar'
|
230
|
+
require 'mime/types/registry'
|
data/lib/mime-types.rb
CHANGED
data/test/minitest_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -*- ruby encoding: utf-8 -*-
|
2
4
|
|
3
5
|
require 'mime/type'
|
@@ -6,16 +8,8 @@ require 'fileutils'
|
|
6
8
|
gem 'minitest'
|
7
9
|
require 'fivemat/minitest/autorun'
|
8
10
|
require 'minitest/focus'
|
11
|
+
require 'minitest/rg'
|
12
|
+
require 'minitest-bonus-assertions'
|
13
|
+
require 'minitest/hooks'
|
9
14
|
|
10
|
-
|
11
|
-
def assert_deprecated name, message = 'and will be removed'
|
12
|
-
name = Regexp.escape(name)
|
13
|
-
message = Regexp.escape(message)
|
14
|
-
|
15
|
-
assert_output nil, /#{name} is deprecated #{message}./ do
|
16
|
-
yield
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
Minitest::Test.send(:include, self)
|
21
|
-
end
|
15
|
+
ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'yes'
|