mime-types 2.6.2 → 2.99

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,11 +39,6 @@ class MIME::Type::Columnar < MIME::Type
39
39
  super
40
40
  end
41
41
 
42
- def references(*) # :nodoc:
43
- @container.send(:load_references) unless defined?(@references)
44
- super if @references
45
- end
46
-
47
42
  def registered? # :nodoc:
48
43
  @container.send(:load_registered) unless defined?(@registered)
49
44
  super
@@ -54,16 +49,6 @@ class MIME::Type::Columnar < MIME::Type
54
49
  super
55
50
  end
56
51
 
57
- def system?(*) # :nodoc:
58
- @container.send(:load_system) unless defined?(@system)
59
- super
60
- end
61
-
62
- def system # :nodoc:
63
- @container.send(:load_system) unless defined?(@system)
64
- @system
65
- end
66
-
67
52
  def xrefs # :nodoc:
68
53
  @container.send(:load_xrefs) unless defined?(@xrefs)
69
54
  @xrefs
@@ -81,30 +66,23 @@ class MIME::Type::Columnar < MIME::Type
81
66
 
82
67
  def to_a # :nodoc:
83
68
  @container.send(:load_encoding) unless defined?(@encoding)
84
- @container.send(:load_system) unless defined?(@system)
85
69
  @container.send(:load_docs) unless defined?(@docs)
86
- @container.send(:load_references) unless defined?(@references)
87
70
  super
88
71
  end
89
72
 
90
73
  def to_hash # :nodoc:
91
74
  @container.send(:load_encoding) unless defined?(@encoding)
92
- @container.send(:load_system) unless defined?(@system)
93
75
  @container.send(:load_docs) unless defined?(@docs)
94
- @container.send(:load_references) unless defined?(@references)
95
76
  super
96
77
  end
97
78
 
98
79
  def encode_with(coder) # :nodoc:
99
80
  @container.send(:load_friendly) unless defined?(@friendly)
100
81
  @container.send(:load_encoding) unless defined?(@encoding)
101
- @container.send(:load_system) unless defined?(@system)
102
82
  @container.send(:load_docs) unless defined?(@docs)
103
- @container.send(:load_references) unless defined?(@references)
104
83
  @container.send(:load_obsolete) unless defined?(@obsolete)
105
84
  @container.send(:load_use_instead) unless defined?(@use_instead)
106
85
  @container.send(:load_xrefs) unless defined?(@xrefs)
107
- @container.send(:load_system) unless defined?(@system)
108
86
  @container.send(:load_registered) unless defined?(@registered)
109
87
  @container.send(:load_signature) unless defined?(@signature)
110
88
  super
@@ -130,17 +130,15 @@ class MIME::Types
130
130
  # 1. Complete definitions sort before incomplete ones;
131
131
  # 2. IANA-registered definitions sort before LTSW-recorded
132
132
  # definitions.
133
- # 3. Generic definitions sort before platform-specific ones;
134
- # 4. Current definitions sort before obsolete ones;
135
- # 5. Obsolete definitions with use-instead clauses sort before those
133
+ # 3. Current definitions sort before obsolete ones;
134
+ # 4. Obsolete definitions with use-instead clauses sort before those
136
135
  # without;
137
- # 6. Obsolete definitions use-instead clauses are compared.
138
- # 7. Sort on name.
136
+ # 5. Obsolete definitions use-instead clauses are compared.
137
+ # 6. Sort on name.
139
138
  #
140
- # An additional flag of :platform (finds only MIME::Types for the current
141
- # platform) is currently supported but deprecated.
139
+ # The previously supported (but deprecated) <tt>:platform</tt> flag is now ignored.
142
140
  def [](type_id, flags = {})
143
- if flags[:platform]
141
+ if flags.key?(:platform)
144
142
  MIME::Types.deprecated(self, __method__, 'using the :platform flag')
145
143
  end
146
144
 
@@ -169,19 +167,16 @@ class MIME::Types
169
167
  # puts MIME::Types.type_for(%w(citydesk.xml citydesk.gif))
170
168
  # => [application/xml, image/gif, text/xml]
171
169
  #
172
- # If +platform+ is +true+, then only file types that are specific to the
173
- # current platform will be returned. This parameter has been deprecated.
174
- def type_for(filename, platform = false)
170
+ # The deprecated +platform+ flag is ignored.
171
+ def type_for(filename, platform = :deprecated)
175
172
  types = Array(filename).flat_map { |fn|
176
173
  @extension_index[fn.chomp.downcase[/\.?([^.]*?)$/, 1]]
177
174
  }.compact.sort { |a, b| a.priority_compare(b) }.uniq
178
175
 
179
- if platform
176
+ unless platform == :deprecated
180
177
  MIME::Types.deprecated(self, __method__, 'using the platform parameter')
181
- types.select(&:platform?)
182
- else
183
- types
184
178
  end
179
+ types
185
180
  end
186
181
  alias_method :of, :type_for
187
182
 
@@ -253,7 +248,7 @@ Type #{type} is already registered as a variant of #{type.simplified}.
253
248
  end
254
249
 
255
250
  # MIME::Types#type_for against the default MIME::Types registry.
256
- def type_for(filename, platform = false)
251
+ def type_for(filename, platform = :deprecated)
257
252
  __types__.type_for(filename, platform)
258
253
  end
259
254
  alias_method :of, :type_for
@@ -317,7 +312,6 @@ Type #{type} is already registered as a variant of #{type.simplified}.
317
312
 
318
313
  def prune_matches(matches, flags)
319
314
  matches.delete_if { |e| !e.complete? } if flags[:complete]
320
- matches.delete_if { |e| !e.platform? } if flags[:platform]
321
315
  matches.delete_if { |e| !e.registered? } if flags[:registered]
322
316
  matches
323
317
  end
@@ -81,12 +81,6 @@ module MIME::Types::Columnar
81
81
  end
82
82
  end
83
83
 
84
- def load_references
85
- each_file_line('references') do |type, line|
86
- type.instance_variable_set(:@references, arr(line))
87
- end
88
- end
89
-
90
84
  def load_registered
91
85
  each_file_line('registered') do |type, line|
92
86
  type.registered = bool(line)
@@ -99,12 +93,6 @@ module MIME::Types::Columnar
99
93
  end
100
94
  end
101
95
 
102
- def load_system
103
- each_file_line('system') do |type, line|
104
- type.system = (line unless line == '-'.freeze)
105
- end
106
- end
107
-
108
96
  def load_xrefs
109
97
  each_file_line('xrefs') { |type, line| type.xrefs = dict(line) }
110
98
  end
@@ -169,8 +169,8 @@ class MIME::Types::Loader
169
169
  fail BadV1Format, line
170
170
  end
171
171
 
172
- unregistered, obsolete, platform, mediatype, subtype, extensions,
173
- encoding, urls, docs, _ = *m.captures
172
+ unregistered, obsolete, _, mediatype, subtype, extensions, encoding,
173
+ urls, docs, _ = *m.captures
174
174
 
175
175
  next if mediatype.nil?
176
176
 
@@ -187,15 +187,10 @@ class MIME::Types::Loader
187
187
  mime_type = MIME::Type.new("#{mediatype}/#{subtype}") do |t|
188
188
  t.extensions = extensions
189
189
  t.encoding = encoding
190
- t.system = platform
191
190
  t.obsolete = obsolete
192
191
  t.registered = false if unregistered
193
192
  t.use_instead = use_instead
194
193
  t.docs = docs
195
-
196
- # This is being removed. Cheat to silence it for now.
197
- t.instance_variable_set :@references,
198
- Array(urls).flatten.compact.uniq
199
194
  end
200
195
 
201
196
  mime.add_type(mime_type, true)
@@ -29,11 +29,9 @@ class Convert::Columnar < Convert
29
29
 
30
30
  required_file('encoding')
31
31
  optional_file('docs')
32
- optional_file('system')
33
32
  bool_file('obsolete')
34
33
  bool_file('registered')
35
34
  bool_file('signature')
36
- array_file('references')
37
35
  dict_file('xrefs')
38
36
  dict_file('friendly')
39
37
  optional_file('use_instead', 'use-instead')
@@ -85,7 +85,6 @@ class IANARegistry
85
85
 
86
86
  if types.empty?
87
87
  MIME::Type.new(content_type) do |mt|
88
- mt.references = %w(IANA) + refs
89
88
  mt.xrefs = xrefs
90
89
  mt.registered = true
91
90
  mt.obsolete = obsolete if obsolete
@@ -94,7 +93,6 @@ class IANARegistry
94
93
  end
95
94
  else
96
95
  types.each { |mt|
97
- mt.references = %w(IANA) + refs
98
96
  mt.registered = true
99
97
  mt.xrefs = xrefs
100
98
  mt.obsolete = obsolete if obsolete
@@ -1 +1 @@
1
- [{"content-type":"application/smil","encoding":"8bit","extensions":["smi","smil"],"obsolete":true,"use-instead":"application/smil+xml","references":["IANA","RFC4536"],"registered":true},{"content-type":"audio/vnd.qcelp","encoding":"base64","extensions":["qcp"],"obsolete":true,"use-instead":"audio/QCELP","references":["IANA","RFC3625"],"registered":true},{"content-type":"image/bmp","encoding":"base64","extensions":["bmp"],"obsolete":true,"use-instead":"image/x-bmp","registered":false},{"content-type":"application/acad","encoding":"base64","references":["LTSW"],"registered":false},{"content-type":"audio/webm","encoding":"base64","extensions":["webm"],"references":["{WebM=http://www.webmproject.org/code/specs/container/}"],"registered":false},{"content-type":"image/pjpeg","docs":"Fixes a bug with IE6 and progressive JPEGs","encoding":"base64","registered":false},{"content-type":"application/1d-interleaved-parityfec","encoding":"base64","references":["IANA","RFC6015"],"registered":true},{"content-type":"audio/1d-interleaved-parityfec","encoding":"base64","references":["IANA","RFC6015"],"registered":true},{"content-type":"application/x-apple-diskimage","encoding":"base64","extensions":["dmg"],"registered":false,"system":"mac"}]
1
+ [{"content-type":"application/smil","encoding":"8bit","extensions":["smi","smil"],"obsolete":true,"use-instead":"application/smil+xml","registered":true},{"content-type":"audio/vnd.qcelp","encoding":"base64","extensions":["qcp"],"obsolete":true,"use-instead":"audio/QCELP","registered":true},{"content-type":"image/bmp","encoding":"base64","extensions":["bmp"],"obsolete":true,"use-instead":"image/x-bmp","registered":false},{"content-type":"application/acad","encoding":"base64","registered":false},{"content-type":"audio/webm","encoding":"base64","extensions":["webm"],"registered":false},{"content-type":"image/pjpeg","docs":"Fixes a bug with IE6 and progressive JPEGs","encoding":"base64","registered":false},{"content-type":"application/1d-interleaved-parityfec","encoding":"base64","registered":true},{"content-type":"audio/1d-interleaved-parityfec","encoding":"base64","registered":true},{"content-type":"application/x-apple-diskimage","encoding":"base64","extensions":["dmg"],"registered":false}]
@@ -7,9 +7,6 @@
7
7
  - smil
8
8
  obsolete: true
9
9
  use-instead: application/smil+xml
10
- references:
11
- - IANA
12
- - RFC4536
13
10
  registered: true
14
11
  - !ruby/object:MIME::Type
15
12
  content-type: audio/vnd.qcelp
@@ -18,9 +15,6 @@
18
15
  - qcp
19
16
  obsolete: true
20
17
  use-instead: audio/QCELP
21
- references:
22
- - IANA
23
- - RFC3625
24
18
  registered: true
25
19
  - !ruby/object:MIME::Type
26
20
  content-type: image/bmp
@@ -33,16 +27,12 @@
33
27
  - !ruby/object:MIME::Type
34
28
  content-type: application/acad
35
29
  encoding: base64
36
- references:
37
- - LTSW
38
30
  registered: false
39
31
  - !ruby/object:MIME::Type
40
32
  content-type: audio/webm
41
33
  encoding: base64
42
34
  extensions:
43
35
  - webm
44
- references:
45
- - ! '{WebM=http://www.webmproject.org/code/specs/container/}'
46
36
  registered: false
47
37
  - !ruby/object:MIME::Type
48
38
  content-type: image/pjpeg
@@ -52,16 +42,10 @@
52
42
  - !ruby/object:MIME::Type
53
43
  content-type: application/1d-interleaved-parityfec
54
44
  encoding: base64
55
- references:
56
- - IANA
57
- - RFC6015
58
45
  registered: true
59
46
  - !ruby/object:MIME::Type
60
47
  content-type: audio/1d-interleaved-parityfec
61
48
  encoding: base64
62
- references:
63
- - IANA
64
- - RFC6015
65
49
  registered: true
66
50
  - !ruby/object:MIME::Type
67
51
  content-type: application/x-apple-diskimage
@@ -69,4 +53,3 @@
69
53
  extensions:
70
54
  - dmg
71
55
  registered: false
72
- system: !ruby/regexp /mac/
@@ -4,8 +4,9 @@ require 'mime/type'
4
4
  require 'fileutils'
5
5
 
6
6
  gem 'minitest'
7
- require 'minitest/autorun'
7
+ require 'fivemat/minitest/autorun'
8
8
  require 'minitest/focus'
9
+ require 'minitest/rg'
9
10
 
10
11
  module Minitest::MIMEDeprecated
11
12
  def assert_deprecated name, message = 'and will be removed'
@@ -18,7 +18,7 @@ class TestMIMEType < Minitest::Test
18
18
  js.encoding = '8bit'
19
19
  js.extensions = %w(js sj)
20
20
  assert_deprecated('MIME::Type#references=') do
21
- js.references = %w(IANA RFC4329 {application/javascript=http://www.iana.org/assignments/media-types/application/javascript})
21
+ js.references = :anything
22
22
  end
23
23
  js.registered = true
24
24
 
@@ -30,7 +30,9 @@ class TestMIMEType < Minitest::Test
30
30
  make('text/x-yaml') do |yaml|
31
31
  yaml.extensions = %w(yaml yml)
32
32
  yaml.encoding = '8bit'
33
- yaml.system = 'd9d172f608'
33
+ assert_deprecated('MIME::Type#system=') do
34
+ yaml.system = 'd9d172f608'
35
+ end
34
36
  yaml.friendly('en' => 'YAML Structured Document')
35
37
  end
36
38
  end
@@ -39,7 +41,9 @@ class TestMIMEType < Minitest::Test
39
41
  make('text/x-yaml') do |yaml|
40
42
  yaml.extensions = %w(yaml yml)
41
43
  yaml.encoding = '8bit'
42
- yaml.system = 'd9d172f608'
44
+ assert_deprecated('MIME::Type#system=') do
45
+ yaml.system = 'd9d172f608'
46
+ end
43
47
  yaml.docs = 'Test YAML'
44
48
  end
45
49
  end
@@ -274,18 +278,8 @@ class TestMIMEType < Minitest::Test
274
278
  end
275
279
 
276
280
  def test_platform_eh
277
- yaml = nil
278
281
  assert_deprecated('MIME::Type#platform?') do
279
- yaml = make_yaml_mime_type
280
- refute(yaml.platform?)
281
- end
282
- yaml.system = nil
283
- assert_deprecated('MIME::Type#platform?') do
284
- refute(yaml.platform?)
285
- end
286
- yaml.system = %r{#{RUBY_PLATFORM}}
287
- assert_deprecated('MIME::Type#platform?') do
288
- assert(yaml.platform?)
282
+ refute make_yaml_mime_type.platform?
289
283
  end
290
284
  end
291
285
 
@@ -303,10 +297,6 @@ class TestMIMEType < Minitest::Test
303
297
  tr = make(tl) { |t| t.registered = false }
304
298
  assert_priority([tl, tr], [tl, te], [tr, tl])
305
299
 
306
- tl.system = te.system = nil
307
- tr = make(tl) { |t| t.system = /#{RUBY_PLATFORM}/ }
308
- assert_priority([tl, tr], [tl, te], [tr, tl])
309
-
310
300
  tl.extensions = te.extensions = %w(1)
311
301
  tr = make(tl) { |t| t.extensions = nil }
312
302
  assert_priority([tl, tr], [tl, te], [tr, tl])
@@ -394,39 +384,29 @@ class TestMIMEType < Minitest::Test
394
384
 
395
385
  def test_system
396
386
  assert_deprecated('MIME::Type#system') do
397
- yaml = make_yaml_mime_type
398
- assert_equal(%r{d9d172f608}, yaml.system)
387
+ assert_nil make_yaml_mime_type.system
399
388
  end
400
389
  end
401
390
 
402
391
  def test_system_equals
403
- yaml = make_yaml_mime_type
404
- yaml.system = /win32/
405
392
  assert_deprecated('MIME::Type#system') do
406
- assert_equal(%r{win32}, yaml.system)
407
- end
408
- yaml.system = nil
409
- assert_deprecated('MIME::Type#system') do
410
- assert_nil(yaml.system)
393
+ yaml = make_yaml_mime_type
394
+ yaml.system = /win32/
395
+ assert_nil yaml.system
411
396
  end
412
397
  end
413
398
 
414
399
  def test_system_eh
415
- yaml = make_yaml_mime_type
416
400
  assert_deprecated('MIME::Type#system?') do
417
- assert(yaml.system?)
418
- end
419
- yaml.system = nil
420
- assert_deprecated('MIME::Type#system?') do
421
- refute(yaml.system?)
401
+ refute make_yaml_mime_type.system?
422
402
  end
423
403
  end
424
404
 
425
405
  def test_to_a
426
406
  yaml = make_yaml_mime_type
427
407
  assert_deprecated('MIME::Type#to_a') do
428
- assert_equal(['text/x-yaml', %w(yaml yml), '8bit', /d9d172f608/,
429
- false, [], [], false], yaml.to_a)
408
+ assert_equal [ 'text/x-yaml', %w(yaml yml), '8bit', nil, false, [], [],
409
+ false ], yaml.to_a
430
410
  end
431
411
  end
432
412
 
@@ -438,7 +418,7 @@ class TestMIMEType < Minitest::Test
438
418
  'Content-Type' => 'text/x-yaml',
439
419
  'Content-Transfer-Encoding' => '8bit',
440
420
  'Extensions' => %w(yaml yml),
441
- 'System' => /d9d172f608/,
421
+ 'System' => nil,
442
422
  'Registered' => false,
443
423
  'URL' => [],
444
424
  'Obsolete' => false,
@@ -463,11 +443,7 @@ class TestMIMEType < Minitest::Test
463
443
  v.obsolete = true
464
444
  v.use_instead = 'c/d'
465
445
  }, 'obsolete', 'use-instead')
466
- assert_type_has_keys(make(t) { |v|
467
- assert_deprecated('MIME::Type#references=') { v.references = 'IANA' }
468
- }, 'references')
469
446
  assert_type_has_keys(make(t) { |v| v.signature = true }, 'signature')
470
- assert_type_has_keys(make(t) { |v| v.system = /xyz/ }, 'system')
471
447
  end
472
448
 
473
449
  def test_to_json
@@ -500,24 +476,17 @@ class TestMIMEType < Minitest::Test
500
476
 
501
477
  def test_references
502
478
  assert_deprecated('MIME::Type#references') do
503
- assert_empty(make_yaml_mime_type.references)
479
+ assert_empty make_yaml_mime_type.references
504
480
  end
505
481
  end
506
482
 
507
483
  def test_references_equals
508
484
  yaml = make_yaml_mime_type
509
485
  assert_deprecated('MIME::Type#references=') do
510
- yaml.references = 'IANA'
486
+ yaml.references = :anything
511
487
  end
512
488
  assert_deprecated('MIME::Type#references') do
513
- assert_equal(%w(IANA), yaml.references)
514
- end
515
-
516
- assert_deprecated('MIME::Type#references=') do
517
- yaml.references = %w(IANA IANA)
518
- end
519
- assert_deprecated('MIME::Type#references') do
520
- assert_equal(%w(IANA), yaml.references)
489
+ assert_empty yaml.references
521
490
  end
522
491
  end
523
492
 
@@ -567,55 +536,14 @@ class TestMIMEType < Minitest::Test
567
536
  yaml.url = 'IANA'
568
537
  end
569
538
  assert_deprecated('MIME::Type#url') do
570
- assert_equal(%w(IANA), yaml.url)
539
+ assert_equal [], yaml.url
571
540
  end
572
541
  end
573
542
 
574
543
  def test_urls
575
544
  yaml = make_yaml_mime_type
576
545
  assert_deprecated('MIME::Type#urls') do
577
- assert_empty(yaml.urls)
578
- end
579
-
580
- assert_deprecated('MIME::Type#references=') do
581
- yaml.references = %w(IANA RFC123 DRAFT:xyz [abc])
582
- end
583
-
584
- assert_deprecated('MIME::Type#urls') do
585
- assert_equal(
586
- %w(
587
- http://www.iana.org/assignments/media-types/text/yaml
588
- http://rfc-editor.org/rfc/rfc123.txt
589
- http://datatracker.ietf.org/public/idindex.cgi?command=id_details&filename=xyz
590
- http://www.iana.org/assignments/contact-people.htm#abc
591
- ),
592
- yaml.urls
593
- )
594
- end
595
-
596
- assert_deprecated('MIME::Type#references=') do
597
- yaml.references = '[def=lax]'
598
- end
599
-
600
- assert_deprecated('MIME::Type#urls') do
601
- assert_equal([%w(def http://www.iana.org/assignments/contact-people.htm#lax)],
602
- yaml.urls)
603
- end
604
-
605
- assert_deprecated('MIME::Type#references=') do
606
- yaml.references = '{mno=pqr}'
607
- end
608
-
609
- assert_deprecated('MIME::Type#urls') do
610
- assert_equal([%w(mno pqr)], yaml.urls)
611
- end
612
-
613
- assert_deprecated('MIME::Type#references=') do
614
- yaml.references = 'hoge'
615
- end
616
-
617
- assert_deprecated('MIME::Type#urls') do
618
- assert_equal(%w(hoge), yaml.urls)
546
+ assert_empty yaml.urls
619
547
  end
620
548
  end
621
549