mime-types 2.5 → 2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Contributing.rdoc +72 -20
  4. data/History-Types.rdoc +11 -0
  5. data/History.rdoc +31 -1
  6. data/Manifest.txt +18 -1
  7. data/README.rdoc +142 -61
  8. data/Rakefile +59 -91
  9. data/data/mime-types.json +1 -1
  10. data/data/mime.content_type.column +1907 -0
  11. data/data/mime.docs.column +1907 -0
  12. data/data/mime.encoding.column +1907 -0
  13. data/data/mime.friendly.column +1907 -0
  14. data/data/mime.obsolete.column +1907 -0
  15. data/data/mime.references.column +1907 -0
  16. data/data/mime.registered.column +1907 -0
  17. data/data/mime.signature.column +1907 -0
  18. data/data/mime.system.column +1907 -0
  19. data/data/mime.use_instead.column +1907 -0
  20. data/data/mime.xrefs.column +1907 -0
  21. data/lib/mime/type.rb +192 -119
  22. data/lib/mime/type/columnar.rb +112 -0
  23. data/lib/mime/types.rb +39 -25
  24. data/lib/mime/types/cache.rb +41 -35
  25. data/lib/mime/types/columnar.rb +160 -0
  26. data/lib/mime/types/deprecations.rb +53 -0
  27. data/lib/mime/types/loader.rb +60 -20
  28. data/lib/mime/types/loader_path.rb +2 -3
  29. data/lib/mime/types/logger.rb +35 -0
  30. data/support/apache_mime_types.rb +8 -1
  31. data/support/benchmarks/load.rb +17 -8
  32. data/support/benchmarks/load_allocations.rb +83 -0
  33. data/support/benchmarks/object_counts.rb +41 -0
  34. data/support/convert.rb +44 -24
  35. data/support/convert/columnar.rb +90 -0
  36. data/support/iana_registry.rb +18 -8
  37. data/test/fixture/json.json +1 -1
  38. data/test/fixture/yaml.yaml +3 -6
  39. data/test/minitest_helper.rb +9 -10
  40. data/test/test_mime_type.rb +126 -62
  41. data/test/test_mime_types.rb +15 -11
  42. data/test/test_mime_types_class.rb +16 -14
  43. data/test/test_mime_types_lazy.rb +7 -1
  44. data/test/test_mime_types_loader.rb +17 -8
  45. metadata +54 -12
  46. data/lib/mime.rb +0 -51
@@ -11,7 +11,7 @@ class TestMIMETypes < Minitest::Test
11
11
  MIME::Type.new('application/x-wordperfect6.1'),
12
12
  MIME::Type.new('content-type' => 'application/x-www-form-urlencoded', 'registered' => true),
13
13
  MIME::Type.new(['application/x-gzip', %w(gz)]),
14
- MIME::Type.new(['application/gzip', %W(gz)]))
14
+ MIME::Type.new(['application/gzip', %w(gz)]))
15
15
  end
16
16
 
17
17
  def test_enumerable
@@ -52,15 +52,15 @@ class TestMIMETypes < Minitest::Test
52
52
  end
53
53
 
54
54
  def test_index_with_platform_flag
55
- assert_deprecated("MIME::Types#[]", "using the :platform flag") do
55
+ assert_deprecated('MIME::Types#[]', 'using the :platform flag') do
56
56
  assert_empty(MIME::Types['text/plain', platform: true])
57
57
  end
58
58
  end
59
59
 
60
60
  def test_add
61
- eruby = MIME::Type.new("application/x-eruby") do |t|
62
- t.extensions = "rhtml"
63
- t.encoding = "8bit"
61
+ eruby = MIME::Type.new('application/x-eruby') do |t|
62
+ t.extensions = 'rhtml'
63
+ t.encoding = '8bit'
64
64
  end
65
65
 
66
66
  @mime_types.add(eruby)
@@ -74,9 +74,11 @@ class TestMIMETypes < Minitest::Test
74
74
  assert_equal(%w(image/jpeg), MIME::Types.of('foo.jpeg'))
75
75
  assert_equal(%w(image/jpeg text/plain),
76
76
  MIME::Types.type_for(%w(foo.txt foo.jpeg)))
77
- assert_equal(@mime_types.of('gif', true), @mime_types['image/gif'])
77
+ assert_deprecated('MIME::Types#type_for', 'using the platform parameter') do
78
+ assert_equal(@mime_types.of('gif', true), @mime_types['image/gif'])
79
+ end
78
80
  assert_empty(MIME::Types.type_for('coverallsjson'))
79
- assert_deprecated("MIME::Types#type_for", "using the platform parameter") do
81
+ assert_deprecated('MIME::Types#type_for', 'using the platform parameter') do
80
82
  assert_empty(MIME::Types.type_for('jpeg', true))
81
83
  end
82
84
  assert_empty(@mime_types.type_for('zzz'))
@@ -89,7 +91,7 @@ class TestMIMETypes < Minitest::Test
89
91
  # This tests the instance implementation through the class implementation.
90
92
  def test_add_type_variant
91
93
  xtxp = MIME::Type.new('x-text/x-plain')
92
- assert_deprecated("MIME::Types#add_type_variant", "and will be private") do
94
+ assert_deprecated('MIME::Types#add_type_variant', 'and will be private') do
93
95
  @mime_types.add_type_variant(xtxp)
94
96
  end
95
97
  assert_includes(@mime_types['text/plain'], xtxp)
@@ -102,16 +104,18 @@ class TestMIMETypes < Minitest::Test
102
104
  # This tests the instance implementation through the class implementation.
103
105
  def test_index_extensions
104
106
  xtxp = MIME::Type.new(['x-text/x-plain', %w(tzt)])
105
- assert_deprecated("MIME::Types#index_extensions", "and will be private") do
107
+ assert_deprecated('MIME::Types#index_extensions', 'and will be private') do
106
108
  @mime_types.index_extensions(xtxp)
107
109
  end
108
110
  assert_includes(@mime_types.of('tzt'), xtxp)
109
111
  end
110
112
 
111
113
  def test_defined_types
112
- assert_deprecated("MIME::Types#defined_types") do
114
+ assert_deprecated('MIME::Types#defined_types') do
113
115
  assert_empty(MIME::Types.new.defined_types)
114
116
  end
115
- refute_empty(@mime_types.defined_types)
117
+ assert_deprecated('MIME::Types#defined_types') do
118
+ refute_empty(@mime_types.defined_types)
119
+ end
116
120
  end
117
121
  end
@@ -16,7 +16,7 @@ class TestMIMETypesQueryClassMethods < Minitest::Test
16
16
 
17
17
  def test_load_from_file
18
18
  fn = File.expand_path('../fixture/old-data', __FILE__)
19
- assert_deprecated("MIME::Types.load_from_file") do
19
+ assert_deprecated('MIME::Types.load_from_file') do
20
20
  MIME::Types.load_from_file(fn)
21
21
  end
22
22
  end
@@ -53,7 +53,7 @@ class TestMIMETypesQueryClassMethods < Minitest::Test
53
53
  end
54
54
 
55
55
  def test_index_with_platform_flag
56
- assert_deprecated("MIME::Types#[]", "using the :platform flag") do
56
+ assert_deprecated('MIME::Types#[]', 'using the :platform flag') do
57
57
  assert_empty(MIME::Types['text/plain', platform: true])
58
58
  end
59
59
  end
@@ -63,7 +63,7 @@ class TestMIMETypesQueryClassMethods < Minitest::Test
63
63
  assert_equal(%w(image/gif), MIME::Types.of('foo.gif'))
64
64
  assert_equal(%w(application/xml image/gif text/xml),
65
65
  MIME::Types.type_for(%w(xml gif)))
66
- assert_deprecated("MIME::Types#type_for", "using the platform parameter") do
66
+ assert_deprecated('MIME::Types#type_for', 'using the platform parameter') do
67
67
  assert_empty(MIME::Types.type_for('gif', true))
68
68
  end
69
69
  assert_empty(MIME::Types.type_for('zzz'))
@@ -71,16 +71,18 @@ class TestMIMETypesQueryClassMethods < Minitest::Test
71
71
 
72
72
  def test_count
73
73
  assert(MIME::Types.count.nonzero?,
74
- "A lot of types are expected to be known.")
74
+ 'A lot of types are expected to be known.')
75
75
  end
76
76
 
77
77
  def test_cache_file
78
78
  ENV['RUBY_MIME_TYPES_CACHE'] = 'foo'
79
- assert_deprecated("MIME::Types.cache_file") do
79
+ assert_deprecated('MIME::Types.cache_file') do
80
80
  assert_equal('foo', MIME::Types.cache_file)
81
81
  end
82
82
  ENV.delete('RUBY_MIME_TYPES_CACHE')
83
- assert_nil(MIME::Types.cache_file)
83
+ assert_deprecated('MIME::Types.cache_file') do
84
+ assert_nil(MIME::Types.cache_file)
85
+ end
84
86
  end
85
87
  end
86
88
 
@@ -91,37 +93,37 @@ class TestMIMETypesClassMethods < Minitest::Test
91
93
  end
92
94
 
93
95
  def test_add_with_type
94
- MIME::Types.add(MIME::Type.new("application/x-eruby"))
96
+ MIME::Types.add(MIME::Type.new('application/x-eruby'))
95
97
  refute_empty(MIME::Types['application/x-eruby'])
96
98
  end
97
99
 
98
100
  def test_add_with_types
99
101
  mt = MIME::Types.new
100
- mt.add MIME::Type.new("application/x-eruby")
102
+ mt.add MIME::Type.new('application/x-eruby')
101
103
  MIME::Types.add(mt)
102
104
  refute_empty(MIME::Types['application/x-eruby'])
103
105
  end
104
106
 
105
107
  def test_add_with_array
106
- MIME::Types.add([MIME::Type.new("application/x-eruby")])
108
+ MIME::Types.add([MIME::Type.new('application/x-eruby')])
107
109
  refute_empty(MIME::Types['application/x-eruby'])
108
110
  end
109
111
 
110
112
  def test_add_with_noise_suppression
111
113
  assert_silent do
112
- MIME::Types.add(MIME::Type.new("application/x-eruby"))
114
+ MIME::Types.add(MIME::Type.new('application/x-eruby'))
113
115
  end
114
116
  assert_output(nil, %r{application/x-eruby is already registered}) do
115
- MIME::Types.add(MIME::Type.new("application/x-eruby"))
117
+ MIME::Types.add(MIME::Type.new('application/x-eruby'))
116
118
  end
117
119
  assert_silent do
118
- MIME::Types.add(MIME::Type.new("application/x-eruby"), :silent)
120
+ MIME::Types.add(MIME::Type.new('application/x-eruby'), :silent)
119
121
  end
120
122
  end
121
123
 
122
124
  def test_add_type_variant
123
125
  xtxp = MIME::Type.new('x-text/x-plain')
124
- assert_deprecated("MIME::Types#add_type_variant", "and will be private") do
126
+ assert_deprecated('MIME::Types#add_type_variant', 'and will be private') do
125
127
  MIME::Types.add_type_variant(xtxp)
126
128
  end
127
129
  assert_includes(MIME::Types['text/plain'], xtxp)
@@ -129,7 +131,7 @@ class TestMIMETypesClassMethods < Minitest::Test
129
131
 
130
132
  def test_index_extensions
131
133
  xtxp = MIME::Type.new(['x-text/x-plain', %w(tzt)])
132
- assert_deprecated("MIME::Types#index_extensions", "and will be private") do
134
+ assert_deprecated('MIME::Types#index_extensions', 'and will be private') do
133
135
  MIME::Types.index_extensions(xtxp)
134
136
  end
135
137
  assert_includes(MIME::Types.of('tzt'), xtxp)
@@ -5,12 +5,14 @@ require 'minitest_helper'
5
5
 
6
6
  class TestMIMETypesLazy < Minitest::Test
7
7
  def setup
8
+ @cache_file = File.expand_path('../cache.tst', __FILE__)
8
9
  ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'true'
9
- ENV['RUBY_MIME_TYPES_CACHE'] = File.expand_path('../cache.tst', __FILE__)
10
+ ENV['RUBY_MIME_TYPES_CACHE'] = @cache_file
10
11
  MIME::Types::Cache.save
11
12
  end
12
13
 
13
14
  def teardown
15
+ clear_cache_file
14
16
  reset_mime_types
15
17
  if File.exist? ENV['RUBY_MIME_TYPES_CACHE']
16
18
  FileUtils.rm ENV['RUBY_MIME_TYPES_CACHE']
@@ -19,6 +21,10 @@ class TestMIMETypesLazy < Minitest::Test
19
21
  ENV.delete('RUBY_MIME_TYPES_LAZY_LOAD')
20
22
  end
21
23
 
24
+ def clear_cache_file
25
+ FileUtils.rm @cache_file if File.exist? @cache_file
26
+ end
27
+
22
28
  def reset_mime_types
23
29
  MIME::Types.instance_variable_set(:@__types__, nil)
24
30
  MIME::Types.send(:load_default_mime_types)
@@ -12,21 +12,28 @@ class TestMIMETypesLoader < Minitest::Test
12
12
 
13
13
  def assert_correctly_loaded(types)
14
14
  assert_includes(types, 'application/1d-interleaved-parityfec')
15
- assert_includes(types['application/acad'].first.references, 'LTSW')
16
- assert_equal([%w(WebM http://www.webmproject.org/code/specs/container/)],
17
- types['audio/webm'].first.urls)
15
+ assert_deprecated('MIME::Type#references') do
16
+ assert_includes(types['application/acad'].first.references, 'LTSW')
17
+ end
18
+ assert_deprecated('MIME::Type#urls') do
19
+ assert_equal([%w(WebM http://www.webmproject.org/code/specs/container/)],
20
+ types['audio/webm'].first.urls)
21
+ end
18
22
  assert_equal(%w(webm), types['audio/webm'].first.extensions)
19
23
  refute(types['audio/webm'].first.registered?)
20
24
 
21
25
  assert_equal('Fixes a bug with IE6 and progressive JPEGs',
22
26
  types['image/pjpeg'].first.docs)
23
27
 
24
- assert(types['application/x-apple-diskimage'].first.system?)
25
- assert_equal(/mac/, types['application/x-apple-diskimage'].first.system)
28
+ assert_deprecated('MIME::Type#system?') do
29
+ assert(types['application/x-apple-diskimage'].first.system?)
30
+ end
31
+ assert_deprecated('MIME::Type#system') do
32
+ assert_equal(/mac/, types['application/x-apple-diskimage'].first.system)
33
+ end
26
34
 
27
35
  assert(types['audio/vnd.qcelp'].first.obsolete?)
28
- assert_equal(%w(audio/QCELP),
29
- types['audio/vnd.qcelp'].first.use_instead)
36
+ assert_equal('audio/QCELP', types['audio/vnd.qcelp'].first.use_instead)
30
37
  end
31
38
 
32
39
  def test_load_yaml
@@ -38,7 +45,9 @@ class TestMIMETypesLoader < Minitest::Test
38
45
  end
39
46
 
40
47
  def test_load_v1
41
- assert_correctly_loaded(@loader.load_v1)
48
+ assert_deprecated('MIME::Types::Loader.load_v1') do
49
+ assert_correctly_loaded(@loader.load_v1)
50
+ end
42
51
  end
43
52
 
44
53
  def test_malformed_v1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mime-types
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.5'
4
+ version: '2.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Ziegler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-25 00:00:00.000000000 Z
11
+ date: 2015-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '1.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: minitest-focus
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rake
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -188,16 +202,27 @@ description: |-
188
202
  HTTP traffic, to indicate the type of content which is transmitted. The
189
203
  mime-types library provides the ability for detailed information about MIME
190
204
  entities (provided as an enumerable collection of MIME::Type objects) to be
191
- determined and used programmatically. There are many types defined by RFCs and
192
- vendors, so the list is long but by definition incomplete; don't hesitate to
193
- add additional type definitions (see Contributing.rdoc). The primary sources
194
- for MIME type definitions found in mime-types is the
195
- {IANA Media Types registry}[https://www.iana.org/assignments/media-types/media-types.xhtml],
196
- RFCs, and W3C recommendations. It conforms to RFCs 2045 and 2231.
205
+ determined and used. There are many types defined by RFCs and vendors, so the
206
+ list is long but by definition incomplete; don't hesitate to add additional
207
+ type definitions. MIME type definitions found in mime-types are from RFCs, W3C
208
+ recommendations, the {IANA Media Types
209
+ registry}[https://www.iana.org/assignments/media-types/media-types.xhtml], and
210
+ user contributions. It conforms to RFCs 2045 and 2231.
211
+
212
+ This is release 2.6 with two new experimental features. The first new feature
213
+ is a new default registry storage format that greatly reduces the initial
214
+ memory use of the mime-types library. This feature is enabled by requiring
215
+ +mime/types/columnar+ instead of +mime/types+ with a small performance cost and
216
+ no change in *total* memory use if certain methods are called (see {Columnar
217
+ Store}[#columnar-store] for more details). The second new feature is a logger
218
+ interface that conforms to the expectations of an ActiveSupport::Logger so that
219
+ warnings can be written to an application's log rather than the default
220
+ location for +warn+. This interface may be used for other logging purposes in
221
+ the future.
197
222
 
198
- This is release 2.5 with a couple of bug fixes, updating to the latest IANA
199
- type registry, and adding a user-contributed type. mime-types 2.x supports Ruby
200
- 1.9.2 or later.
223
+ mime-types 2.6 is the last planned version of mime-types 2.x, so deprecation
224
+ warnings are no longer cached but provided every time the method is called.
225
+ mime-types 2.6 supports Ruby 1.9.2 or later.
201
226
  email:
202
227
  - halostatue@gmail.com
203
228
  executables: []
@@ -224,18 +249,35 @@ files:
224
249
  - README.rdoc
225
250
  - Rakefile
226
251
  - data/mime-types.json
252
+ - data/mime.content_type.column
253
+ - data/mime.docs.column
254
+ - data/mime.encoding.column
255
+ - data/mime.friendly.column
256
+ - data/mime.obsolete.column
257
+ - data/mime.references.column
258
+ - data/mime.registered.column
259
+ - data/mime.signature.column
260
+ - data/mime.system.column
261
+ - data/mime.use_instead.column
262
+ - data/mime.xrefs.column
227
263
  - docs/COPYING.txt
228
264
  - docs/artistic.txt
229
265
  - lib/mime-types.rb
230
- - lib/mime.rb
231
266
  - lib/mime/type.rb
267
+ - lib/mime/type/columnar.rb
232
268
  - lib/mime/types.rb
233
269
  - lib/mime/types/cache.rb
270
+ - lib/mime/types/columnar.rb
271
+ - lib/mime/types/deprecations.rb
234
272
  - lib/mime/types/loader.rb
235
273
  - lib/mime/types/loader_path.rb
274
+ - lib/mime/types/logger.rb
236
275
  - support/apache_mime_types.rb
237
276
  - support/benchmarks/load.rb
277
+ - support/benchmarks/load_allocations.rb
278
+ - support/benchmarks/object_counts.rb
238
279
  - support/convert.rb
280
+ - support/convert/columnar.rb
239
281
  - support/iana_registry.rb
240
282
  - test/bad-fixtures/malformed
241
283
  - test/fixture/json.json
@@ -1,51 +0,0 @@
1
- # -*- ruby encoding: utf-8 -*-
2
-
3
- # The namespace for MIME applications, tools, and libraries.
4
- module MIME # :nodoc:
5
- end
6
-
7
- class << MIME
8
- # Used to mark a method as deprecated in the mime-types interface.
9
- def deprecated(klass, sym, message = nil, &block) # :nodoc:
10
- level = case klass
11
- when Class, Module
12
- '.'
13
- else
14
- klass = klass.class
15
- '#'
16
- end
17
- unless defined?(@__deprecated) and @__deprecated["#{klass}#{level}#{sym}"]
18
- message = case message
19
- when :private, :protected
20
- "and will be #{message}"
21
- when nil
22
- "and will be removed"
23
- else
24
- message
25
- end
26
- warn "#{klass}#{level}#{sym} is deprecated #{message}."
27
- (@__deprecated ||= {})["#{klass}#{level}#{sym}"] = true
28
- block.call if block
29
- end
30
- end
31
-
32
- # MIME::InvalidContentType was moved to MIME::Type::InvalidContentType.
33
- # Provide a single warning about this fact in the interim.
34
- def const_missing(name) # :nodoc:
35
- case name.to_s
36
- when "InvalidContentType"
37
- warn_about_moved_constants(name)
38
- MIME::Type.const_get(name.to_sym)
39
- else
40
- super
41
- end
42
- end
43
-
44
- private
45
- def warn_about_moved_constants(name) # :nodoc:
46
- unless defined?(@__warned_constants) and @__warned_constants[name]
47
- warn "MIME::#{name} is deprecated. Use MIME::Type::#{name} instead."
48
- (@__warned_constants ||= {})[name] = true
49
- end
50
- end
51
- end