mime-types 3.2.2 → 3.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4341a1bdee1841367197d0f06ed6fcda8ee1fc3cd4347c6aa949fe942f247d2c
4
- data.tar.gz: a7dd6d594e0029c2e6e4d8d342c3b8a46b94d05f2281cd30218a31fcbec8ec04
3
+ metadata.gz: c7c3e98bd6269827964418e761cda4c4699372a96b842c0bf161357201025974
4
+ data.tar.gz: e57d04551653914d1d184e35f0531be89665a23f4442a658f0fe5b59e7c61cec
5
5
  SHA512:
6
- metadata.gz: 143d9bcc08f707d6e4cef9cee51d94581183ac6264180b261939215311368606fed8168832e96c7908f1926409c4d50c9a7d8216009070dda473aeb20465ba3e
7
- data.tar.gz: 6e14198fc2b2c67c6b4f1e71d2f1f0442050ddec22f1be28533290badc01a7d3e8d5bc3e476f0af95c31c260171172d5bc777adee5fa30d2bb4838c2cc078d43
6
+ metadata.gz: 5e53279a2f70e31beba311206b779f175d4b0f5e516b858c0d6154787f3970bf0b977c0fb91a5739a8dce8a3a89958b58984be1d70ab9b81ca17f9e619bf920a
7
+ data.tar.gz: a2e8e7bf38b05e8536e4892ff2c3a0cdf30a7306c54620af78f36f5db77173bc3bb8ca47010527e8d74f3efd4eeb2fd937208d7951b6703764319d7d885b12b9
@@ -115,6 +115,7 @@ Thanks to everyone else who has contributed to mime-types over the years:
115
115
  * Hans de Graaff
116
116
  * Henrik Hodne
117
117
  * Janko Marohnić
118
+ * Jean Boussier
118
119
  * Jeremy Evans
119
120
  * Juanito Fatas
120
121
  * Jun Aruga
@@ -124,6 +125,7 @@ Thanks to everyone else who has contributed to mime-types over the years:
124
125
  * Martin d'Allens
125
126
  * Mauricio Linhares
126
127
  * Nicolas Leger
128
+ * Nicholas La Roux
127
129
  * nycvotes-dev
128
130
  * Postmodern
129
131
  * Richard Hirner
data/History.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 3.3 / 2019-09-04
2
+
3
+ * 1 minor enhancement
4
+
5
+ * Jean Boussier reduced memory usage for Ruby versions 2.3 or higher by
6
+ interning various string values in each type. This is done with a
7
+ backwards-compatible call that _freezes_ the strings on older
8
+ versions of Ruby. [#141][]
9
+
10
+ * Administrivia:
11
+
12
+ * Nicholas La Roux updated Travis build configurations. [#139][]
13
+
1
14
  ## 3.2.2 / 2018-08-12
2
15
 
3
16
  * Hiroto Fukui removed a stray `debugger` statement that I had used in
@@ -50,7 +63,7 @@
50
63
  * Documentation Changes:
51
64
 
52
65
  * Supporting files are now Markdown instead of rdoc, except for the
53
- README.
66
+ README.
54
67
 
55
68
  * The history file has been modified to remove all history prior to 3.0.
56
69
  This history can be found in previous commits.
@@ -203,6 +216,8 @@
203
216
  [#135]: https://github.com/mime-types/ruby-mime-types/pull/135
204
217
  [#136]: https://github.com/mime-types/ruby-mime-types/issues/136
205
218
  [#137]: https://github.com/mime-types/ruby-mime-types/pull/137
219
+ [#139]: https://github.com/mime-types/ruby-mime-types/pull/139
220
+ [#141]: https://github.com/mime-types/ruby-mime-types/pull/141
206
221
  [Code-of-Conduct.md]: Code-of-Conduct_md.html
207
222
  [Contributor Covenant]: http://contributor-covenant.org
208
223
  [mime-types-data]: https://github.com/mime-types/mime-types-data
data/Licence.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## Licence
2
2
 
3
- * Copyright 2003–2018 Austin Ziegler and contributors.
3
+ * Copyright 2003–2019 Austin Ziegler and contributors.
4
4
 
5
5
  The software in this repository is made available under the MIT license.
6
6
 
data/Rakefile CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby encoding: utf-8 -*-
4
-
5
3
  require 'rubygems'
6
4
  require 'hoe'
7
5
  require 'rake/clean'
@@ -37,7 +35,7 @@ spec = Hoe.spec 'mime-types' do
37
35
  extra_dev_deps << ['minitest-bonus-assertions', '~> 3.0']
38
36
  extra_dev_deps << ['minitest-hooks', '~> 1.4']
39
37
  extra_dev_deps << ['rake', '>= 10.0', '< 13.0']
40
- extra_dev_deps << ['fivemat', '~> 1.3' ]
38
+ extra_dev_deps << ['fivemat', '~> 1.3']
41
39
  extra_dev_deps << ['minitest-rg', '~> 5.2']
42
40
 
43
41
  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.0')
@@ -56,7 +54,7 @@ namespace :benchmark do
56
54
  end
57
55
 
58
56
  desc 'Benchmark Load Times'
59
- task :load, [ :repeats ] => 'benchmark:support' do |_, args|
57
+ task :load, [:repeats] => 'benchmark:support' do |_, args|
60
58
  require 'benchmarks/load'
61
59
  Benchmarks::Load.report(
62
60
  File.join(Rake.application.original_dir, 'lib'),
@@ -65,7 +63,7 @@ namespace :benchmark do
65
63
  end
66
64
 
67
65
  desc 'Allocation counts'
68
- task :allocations, [ :top_x, :mime_types_only ] => 'benchmark:support' do |_, args|
66
+ task :allocations, [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
69
67
  require 'benchmarks/load_allocations'
70
68
  Benchmarks::LoadAllocations.report(
71
69
  top_x: args.top_x,
@@ -74,7 +72,7 @@ namespace :benchmark do
74
72
  end
75
73
 
76
74
  desc 'Columnar allocation counts'
77
- task 'allocations:columnar', [ :top_x, :mime_types_only ] => 'benchmark:support' do |_, args|
75
+ task 'allocations:columnar', [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
78
76
  require 'benchmarks/load_allocations'
79
77
  Benchmarks::LoadAllocations.report(
80
78
  columnar: true,
@@ -84,7 +82,7 @@ namespace :benchmark do
84
82
  end
85
83
 
86
84
  desc 'Columnar allocation counts (full load)'
87
- task 'allocations:columnar:full', [ :top_x, :mime_types_only ] => 'benchmark:support' do |_, args|
85
+ task 'allocations:columnar:full', [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
88
86
  require 'benchmarks/load_allocations'
89
87
  Benchmarks::LoadAllocations.report(
90
88
  columnar: true,
@@ -94,6 +92,36 @@ namespace :benchmark do
94
92
  )
95
93
  end
96
94
 
95
+ desc 'Memory profiler'
96
+ task :memory, [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
97
+ require 'benchmarks/memory_profiler'
98
+ Benchmarks::ProfileMemory.report(
99
+ mime_types_only: args.mime_types_only,
100
+ top_x: args.top_x
101
+ )
102
+ end
103
+
104
+ desc 'Columnar memory profiler'
105
+ task 'memory:columnar', [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
106
+ require 'benchmarks/memory_profiler'
107
+ Benchmarks::ProfileMemory.report(
108
+ columnar: true,
109
+ mime_types_only: args.mime_types_only,
110
+ top_x: args.top_x
111
+ )
112
+ end
113
+
114
+ desc 'Columnar allocation counts (full load)'
115
+ task 'memory:columnar:full', [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
116
+ require 'benchmarks/memory_profiler'
117
+ Benchmarks::ProfileMemory.report(
118
+ columnar: true,
119
+ full: true,
120
+ top_x: args.top_x,
121
+ mime_types_only: args.mime_types_only
122
+ )
123
+ end
124
+
97
125
  desc 'Object counts'
98
126
  task objects: 'benchmark:support' do
99
127
  require 'benchmarks/object_counts'
@@ -131,7 +159,7 @@ namespace :profile do
131
159
  '-R', 'mime/types',
132
160
  '-s', 'self',
133
161
  '-p', 'multi',
134
- '-f', "#{output}",
162
+ '-f', output.to_s,
135
163
  script.to_s
136
164
  ]
137
165
  ruby args.join(' ')
@@ -194,7 +222,7 @@ namespace :convert do
194
222
  rdoc = name
195
223
  mark = "#{File.basename(name, '.rdoc')}.md"
196
224
 
197
- file mark => [ rdoc, :setup ] do |t|
225
+ file mark => [rdoc, :setup] do |t|
198
226
  puts "#{rdoc} => #{mark}"
199
227
  File.open(t.name, 'wb') { |target|
200
228
  target.write @doc_converter.convert(IO.read(t.prerequisites.first))
@@ -203,7 +231,7 @@ namespace :convert do
203
231
 
204
232
  CLEAN.add mark
205
233
 
206
- task run: [ mark ]
234
+ task run: [mark]
207
235
  end
208
236
  end
209
237
 
@@ -211,7 +239,7 @@ namespace :convert do
211
239
  task docs: 'convert:docs:run'
212
240
  end
213
241
 
214
- task 'deps:top', [ :number ] do |_, args|
242
+ task 'deps:top', [:number] do |_, args|
215
243
  require 'net/http'
216
244
  require 'json'
217
245
 
@@ -57,17 +57,17 @@ class MIME::Type
57
57
  end
58
58
 
59
59
  # The released version of the mime-types library.
60
- VERSION = '3.2.2'
60
+ VERSION = '3.3'
61
61
 
62
62
  include Comparable
63
63
 
64
64
  # :stopdoc:
65
65
  # TODO verify mime-type character restrictions; I am pretty sure that this is
66
66
  # too wide open.
67
- MEDIA_TYPE_RE = %r{([-\w.+]+)/([-\w.+]*)}
68
- I18N_RE = %r{[^[:alnum:]]}
69
- BINARY_ENCODINGS = %w(base64 8bit)
70
- ASCII_ENCODINGS = %w(7bit quoted-printable)
67
+ MEDIA_TYPE_RE = %r{([-\w.+]+)/([-\w.+]*)}.freeze
68
+ I18N_RE = /[^[:alnum:]]/.freeze
69
+ BINARY_ENCODINGS = %w(base64 8bit).freeze
70
+ ASCII_ENCODINGS = %w(7bit quoted-printable).freeze
71
71
  # :startdoc:
72
72
 
73
73
  private_constant :MEDIA_TYPE_RE, :I18N_RE, :BINARY_ENCODINGS,
@@ -301,7 +301,7 @@ class MIME::Type
301
301
 
302
302
  # Returns the default encoding for the MIME::Type based on the media type.
303
303
  def default_encoding
304
- (@media_type == 'text') ? 'quoted-printable' : 'base64'
304
+ @media_type == 'text' ? 'quoted-printable' : 'base64'
305
305
  end
306
306
 
307
307
  ##
@@ -321,7 +321,7 @@ class MIME::Type
321
321
 
322
322
  # Returns +true+ if the media type is obsolete.
323
323
  attr_accessor :obsolete
324
- alias_method :obsolete?, :obsolete
324
+ alias obsolete? obsolete
325
325
 
326
326
  # The documentation for this MIME::Type.
327
327
  attr_accessor :docs
@@ -331,7 +331,7 @@ class MIME::Type
331
331
  # call-seq:
332
332
  # text_plain.friendly # => "Text File"
333
333
  # text_plain.friendly('en') # => "Text File"
334
- def friendly(lang = 'en'.freeze)
334
+ def friendly(lang = 'en')
335
335
  @friendly ||= {}
336
336
 
337
337
  case lang
@@ -367,8 +367,8 @@ class MIME::Type
367
367
  attr_reader :xrefs
368
368
 
369
369
  ##
370
- def xrefs=(x) # :nodoc:
371
- @xrefs = MIME::Types::Container.new(x)
370
+ def xrefs=(xrefs) # :nodoc:
371
+ @xrefs = MIME::Types::Container.new(xrefs)
372
372
  end
373
373
 
374
374
  # The decoded cross-reference URL list for this MIME::Type.
@@ -381,7 +381,7 @@ class MIME::Type
381
381
 
382
382
  # Indicates whether the MIME type has been registered with IANA.
383
383
  attr_accessor :registered
384
- alias_method :registered?, :registered
384
+ alias registered? registered
385
385
 
386
386
  # MIME types can be specified to be sent across a network in particular
387
387
  # formats. This method returns +true+ when the MIME::Type encoding is set
@@ -399,7 +399,7 @@ class MIME::Type
399
399
 
400
400
  # Indicateswhether the MIME type is declared as a signature type.
401
401
  attr_accessor :signature
402
- alias_method :signature?, :signature
402
+ alias signature? signature
403
403
 
404
404
  # Returns +true+ if the MIME::Type specifies an extension list,
405
405
  # indicating that it is a complete MIME::Type.
@@ -438,17 +438,15 @@ class MIME::Type
438
438
  #
439
439
  # This method should be considered a private implementation detail.
440
440
  def encode_with(coder)
441
- coder['content-type'] = @content_type
442
- coder['docs'] = @docs unless @docs.nil? or @docs.empty?
443
- unless @friendly.nil? or @friendly.empty?
444
- coder['friendly'] = @friendly
445
- end
446
- coder['encoding'] = @encoding
447
- coder['extensions'] = @extensions.to_a unless @extensions.empty?
441
+ coder['content-type'] = @content_type
442
+ coder['docs'] = @docs unless @docs.nil? or @docs.empty?
443
+ coder['friendly'] = @friendly unless @friendly.nil? or @friendly.empty?
444
+ coder['encoding'] = @encoding
445
+ coder['extensions'] = @extensions.to_a unless @extensions.empty?
448
446
  coder['preferred-extension'] = @preferred_extension if @preferred_extension
449
447
  if obsolete?
450
- coder['obsolete'] = obsolete?
451
- coder['use-instead'] = use_instead if use_instead
448
+ coder['obsolete'] = obsolete?
449
+ coder['use-instead'] = use_instead if use_instead
452
450
  end
453
451
  unless xrefs.empty?
454
452
  {}.tap do |hash|
@@ -458,8 +456,8 @@ class MIME::Type
458
456
  coder['xrefs'] = hash
459
457
  end
460
458
  end
461
- coder['registered'] = registered?
462
- coder['signature'] = signature? if signature?
459
+ coder['registered'] = registered?
460
+ coder['signature'] = signature? if signature?
463
461
  coder
464
462
  end
465
463
 
@@ -504,7 +502,7 @@ class MIME::Type
504
502
  # use with the I18n library.
505
503
  def i18n_key(content_type)
506
504
  simplify_matchdata(match(content_type), joiner: '.') { |e|
507
- e.gsub!(I18N_RE, '-'.freeze)
505
+ e.gsub!(I18N_RE, '-')
508
506
  }
509
507
  end
510
508
 
@@ -521,12 +519,12 @@ class MIME::Type
521
519
 
522
520
  private
523
521
 
524
- def simplify_matchdata(matchdata, remove_x = false, joiner: '/'.freeze)
522
+ def simplify_matchdata(matchdata, remove_x = false, joiner: '/')
525
523
  return nil unless matchdata
526
524
 
527
525
  matchdata.captures.map { |e|
528
526
  e.downcase!
529
- e.sub!(%r{^x-}, ''.freeze) if remove_x
527
+ e.sub!(/^x-/, '') if remove_x
530
528
  yield e if block_given?
531
529
  e
532
530
  }.join(joiner)
@@ -539,11 +537,28 @@ class MIME::Type
539
537
  match = MEDIA_TYPE_RE.match(type_string)
540
538
  fail InvalidContentType, type_string if match.nil?
541
539
 
542
- @content_type = type_string
540
+ @content_type = intern_string(type_string)
543
541
  @raw_media_type, @raw_sub_type = match.captures
544
- @simplified = MIME::Type.simplified(match)
545
- @i18n_key = MIME::Type.i18n_key(match)
542
+ @simplified = intern_string(MIME::Type.simplified(match))
543
+ @i18n_key = intern_string(MIME::Type.i18n_key(match))
546
544
  @media_type, @sub_type = MEDIA_TYPE_RE.match(@simplified).captures
545
+
546
+ @raw_media_type = intern_string(@raw_media_type)
547
+ @raw_sub_type = intern_string(@raw_sub_type)
548
+ @media_type = intern_string(@media_type)
549
+ @sub_type = intern_string(@sub_type)
550
+ end
551
+
552
+ if String.method_defined?(:-@)
553
+ def intern_string(string)
554
+ -string
555
+ end
556
+ else
557
+ # MRI 2.2 and older don't have a method for string interning,
558
+ # so we simply freeze them for keeping a similar interface
559
+ def intern_string(string)
560
+ string.freeze
561
+ end
547
562
  end
548
563
 
549
564
  def xref_map(values, helper)
@@ -551,23 +566,22 @@ class MIME::Type
551
566
  end
552
567
 
553
568
  def xref_url_for_rfc(value)
554
- 'http://www.iana.org/go/%s'.freeze % value
569
+ 'http://www.iana.org/go/%s' % value
555
570
  end
556
571
 
557
572
  def xref_url_for_draft(value)
558
- 'http://www.iana.org/go/%s'.freeze % value.sub(/\ARFC/, 'draft')
573
+ 'http://www.iana.org/go/%s' % value.sub(/\ARFC/, 'draft')
559
574
  end
560
575
 
561
576
  def xref_url_for_rfc_errata(value)
562
- 'http://www.rfc-editor.org/errata_search.php?eid=%s'.freeze % value
577
+ 'http://www.rfc-editor.org/errata_search.php?eid=%s' % value
563
578
  end
564
579
 
565
580
  def xref_url_for_person(value)
566
- 'http://www.iana.org/assignments/media-types/media-types.xhtml#%s'.freeze %
567
- value
581
+ 'http://www.iana.org/assignments/media-types/media-types.xhtml#%s' % value
568
582
  end
569
583
 
570
584
  def xref_url_for_template(value)
571
- 'http://www.iana.org/assignments/media-types/%s'.freeze % value
585
+ 'http://www.iana.org/assignments/media-types/%s' % value
572
586
  end
573
587
  end
@@ -20,7 +20,7 @@ class MIME::Type::Columnar < MIME::Type
20
20
  end
21
21
 
22
22
  def self.column(*methods, file: nil) # :nodoc:
23
- file = methods.first unless file
23
+ file ||= methods.first
24
24
 
25
25
  file_method = :"load_#{file}"
26
26
  methods.each do |m|
@@ -155,7 +155,7 @@ class MIME::Types
155
155
  a.priority_compare(b)
156
156
  }
157
157
  end
158
- alias_method :of, :type_for
158
+ alias of type_for
159
159
 
160
160
  # Add one or more MIME::Type objects to the set of known types. If the
161
161
  # type is already known, a warning will be displayed.
@@ -185,9 +185,9 @@ class MIME::Types
185
185
  # truthy value to suppress that warning.
186
186
  def add_type(type, quiet = false)
187
187
  if !quiet and @type_variants[type.simplified].include?(type)
188
- MIME::Types.logger.warn <<-warning
188
+ MIME::Types.logger.warn <<-WARNING
189
189
  Type #{type} is already registered as a variant of #{type.simplified}.
190
- warning
190
+ WARNING
191
191
  end
192
192
 
193
193
  add_type_variant!(type)
@@ -202,6 +202,7 @@ Type #{type} is already registered as a variant of #{type.simplified}.
202
202
 
203
203
  def reindex_extensions!(mime_type)
204
204
  return unless @type_variants[mime_type.simplified].include?(mime_type)
205
+
205
206
  index_extensions!(mime_type)
206
207
  end
207
208
 
@@ -45,7 +45,7 @@ module MIME::Types::Columnar
45
45
  i = -1
46
46
  column = File.join(@__root__, "mime.#{name}.column")
47
47
 
48
- IO.readlines(column, encoding: 'UTF-8'.freeze).each do |line|
48
+ IO.readlines(column, encoding: 'UTF-8').each do |line|
49
49
  line.chomp!
50
50
 
51
51
  if lookup
@@ -63,7 +63,6 @@ module MIME::Types::Columnar
63
63
  def load_encoding
64
64
  each_file_line('encoding') do |type, line|
65
65
  pool ||= {}
66
- line.freeze
67
66
  type.instance_variable_set(:@encoding, (pool[line] ||= line))
68
67
  end
69
68
  end
@@ -108,11 +107,11 @@ module MIME::Types::Columnar
108
107
  end
109
108
 
110
109
  def dict(line, array: false)
111
- if line == '-'.freeze
110
+ if line == '-'
112
111
  {}
113
112
  else
114
- line.split('|'.freeze).each_with_object({}) { |l, h|
115
- k, v = l.split('^'.freeze)
113
+ line.split('|').each_with_object({}) { |l, h|
114
+ k, v = l.split('^')
116
115
  v = nil if v.empty?
117
116
  h[k] = array ? Array(v) : v
118
117
  }
@@ -120,18 +119,18 @@ module MIME::Types::Columnar
120
119
  end
121
120
 
122
121
  def arr(line)
123
- if line == '-'.freeze
122
+ if line == '-'
124
123
  []
125
124
  else
126
- line.split('|'.freeze).flatten.compact.uniq
125
+ line.split('|').flatten.compact.uniq
127
126
  end
128
127
  end
129
128
 
130
129
  def opt(line)
131
- line unless line == '-'.freeze
130
+ line unless line == '-'
132
131
  end
133
132
 
134
133
  def flag(line)
135
- line == '1'.freeze ? true : false
134
+ line == '1'
136
135
  end
137
136
  end
@@ -22,16 +22,16 @@ class << MIME::Types::Cache
22
22
  if cache.version == MIME::Types::Data::VERSION
23
23
  Marshal.load(cache.data)
24
24
  else
25
- MIME::Types.logger.warn <<-warning.chomp
25
+ MIME::Types.logger.warn <<-WARNING.chomp
26
26
  Could not load MIME::Types cache: invalid version
27
- warning
27
+ WARNING
28
28
  nil
29
29
  end
30
30
  rescue => e
31
- MIME::Types.logger.warn <<-warning.chomp
31
+ MIME::Types.logger.warn <<-WARNING.chomp
32
32
  Could not load MIME::Types cache: #{e}
33
- warning
34
- return nil
33
+ WARNING
34
+ nil
35
35
  end
36
36
 
37
37
  # Attempts to save the types provided to the cache file provided.
@@ -22,12 +22,13 @@ class MIME::Types::Container #:nodoc:
22
22
  end
23
23
 
24
24
  def []=(key, value)
25
- case value
26
- when Set
27
- container[key] = value
28
- else
29
- container[key] = Set[*value]
30
- end
25
+ container[key] =
26
+ case value
27
+ when Set
28
+ value
29
+ else
30
+ Set[*value]
31
+ end
31
32
  end
32
33
 
33
34
  def merge(other)
@@ -37,7 +38,7 @@ class MIME::Types::Container #:nodoc:
37
38
  def merge!(other)
38
39
  tap {
39
40
  other = other.kind_of?(MIME::Types::Container) ? other.container : other
40
- self.container.merge!(other)
41
+ container.merge!(other)
41
42
  normalize
42
43
  }
43
44
  end
@@ -85,6 +86,7 @@ class MIME::Types::Container #:nodoc:
85
86
  def normalize
86
87
  container.each do |k, v|
87
88
  next if v.kind_of?(Set)
89
+
88
90
  container[k] = Set[*v]
89
91
  end
90
92
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby encoding: utf-8 -*-
4
-
5
3
  require 'mime/types/logger'
6
4
 
7
5
  # The namespace for MIME applications, tools, and libraries.
@@ -33,7 +33,7 @@ class << MIME::Types
33
33
  def type_for(filename)
34
34
  __types__.type_for(filename)
35
35
  end
36
- alias_method :of, :type_for
36
+ alias of type_for
37
37
 
38
38
  # MIME::Types#add against the default MIME::Types registry.
39
39
  def add(*types)
@@ -43,13 +43,13 @@ class << MIME::Types
43
43
  private
44
44
 
45
45
  def lazy_load?
46
- if ENV.key?('RUBY_MIME_TYPES_LAZY_LOAD')
47
- MIME::Types.logger.warn <<-WARNING.chomp
46
+ return unless ENV.key?('RUBY_MIME_TYPES_LAZY_LOAD')
47
+
48
+ MIME::Types.logger.warn <<-WARNING.chomp
48
49
  Lazy loading ($RUBY_MIME_TYPES_LAZY_LOAD) is deprecated and will be removed.
49
- WARNING
50
+ WARNING
50
51
 
51
- (lazy = ENV['RUBY_MIME_TYPES_LAZY_LOAD']) && (lazy != 'false')
52
- end
52
+ (lazy = ENV['RUBY_MIME_TYPES_LAZY_LOAD']) && (lazy != 'false')
53
53
  end
54
54
 
55
55
  def __types__
@@ -63,7 +63,7 @@ Lazy loading ($RUBY_MIME_TYPES_LAZY_LOAD) is deprecated and will be removed.
63
63
  end
64
64
 
65
65
  def load_default_mime_types(mode = load_mode)
66
- if @__types__ = MIME::Types::Cache.load
66
+ if (@__types__ = MIME::Types::Cache.load)
67
67
  __instances__.add(@__types__)
68
68
  else
69
69
  @__types__ = MIME::Types::Loader.load(mode)
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby encoding: utf-8 -*-
4
-
5
3
  require 'mime/type'
6
4
  require 'fileutils'
7
5
 
@@ -1,13 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby encoding: utf-8 -*-
4
-
5
3
  require 'mime/types'
6
4
  require 'minitest_helper'
7
5
 
8
6
  describe MIME::Type do
9
- # it { fail }
10
-
11
7
  def mime_type(content_type)
12
8
  MIME::Type.new(content_type) { |mt| yield mt if block_given? }
13
9
  end
@@ -333,8 +329,8 @@ describe MIME::Type do
333
329
  end
334
330
 
335
331
  it 'sorts (2) based on extensions' do
336
- text_1.extensions = ["foo", "bar"]
337
- text_2.extensions = ["foo"]
332
+ text_1.extensions = ['foo', 'bar']
333
+ text_2.extensions = ['foo']
338
334
 
339
335
  assert_priority_same text_1, text_2
340
336
 
@@ -476,7 +472,7 @@ describe MIME::Type do
476
472
 
477
473
  describe '#to_s, #to_str' do
478
474
  it 'represents itself as a string of the canonical content_type' do
479
- assert_equal 'text/plain', "#{text_plain}"
475
+ assert_equal 'text/plain', "#{text_plain}" # rubocop:disable Style/UnneededInterpolation
480
476
  end
481
477
 
482
478
  it 'acts like a string of the canonical content_type for comparison' do
@@ -490,7 +486,7 @@ describe MIME::Type do
490
486
 
491
487
  describe '#xrefs, #xrefs=' do
492
488
  let(:expected) {
493
- MIME::Types::Container.new({ 'rfc' => Set[*%w(rfc1234 rfc5678)] })
489
+ MIME::Types::Container.new('rfc' => Set['rfc1234', 'rfc5678'])
494
490
  }
495
491
 
496
492
  it 'returns the expected results' do
@@ -518,13 +514,13 @@ describe MIME::Type do
518
514
  let(:type) {
519
515
  mime_type('a/b').tap do |t|
520
516
  t.xrefs = {
521
- 'draft' => [ 'RFC1' ],
522
- 'template' => [ 'a/b' ],
523
- 'person' => [ 'p-1' ],
524
- 'rfc' => [ 'rfc-1' ],
525
- 'rfc-errata' => [ 'err-1' ],
526
- 'uri' => [ 'http://example.org' ],
527
- 'text' => [ 'text' ]
517
+ 'draft' => ['RFC1'],
518
+ 'template' => ['a/b'],
519
+ 'person' => ['p-1'],
520
+ 'rfc' => ['rfc-1'],
521
+ 'rfc-errata' => ['err-1'],
522
+ 'uri' => ['http://example.org'],
523
+ 'text' => ['text']
528
524
  }
529
525
  end
530
526
  }
@@ -588,10 +584,10 @@ describe MIME::Type do
588
584
 
589
585
  it 'merges new values from an array parameter' do
590
586
  expected = { 'en' => 'Text files' }
591
- assert_equal expected, text_plain.friendly([ 'en', 'Text files' ])
587
+ assert_equal expected, text_plain.friendly(['en', 'Text files'])
592
588
  expected.update('fr' => 'des fichiers texte')
593
589
  assert_equal expected,
594
- text_plain.friendly([ 'fr', 'des fichiers texte' ])
590
+ text_plain.friendly(['fr', 'des fichiers texte'])
595
591
  end
596
592
 
597
593
  it 'merges new values from a hash parameter' do
@@ -1,13 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby encoding: utf-8 -*-
4
-
5
3
  require 'mime/types'
6
4
  require 'minitest_helper'
7
5
 
8
6
  describe MIME::Types do
9
7
  def mime_types
10
- @mime_types ||= MIME::Types.new.tap do |mt|
8
+ @mime_types ||= MIME::Types.new.tap { |mt|
11
9
  mt.add MIME::Type.new(['text/plain', %w(txt)]),
12
10
  MIME::Type.new(['image/jpeg', %w(jpg jpeg)]),
13
11
  MIME::Type.new('application/x-wordperfect6.1'),
@@ -21,12 +19,12 @@ describe MIME::Types do
21
19
  'extensions' => 'gz',
22
20
  'registered' => true
23
21
  )
24
- end
22
+ }
25
23
  end
26
24
 
27
25
  describe 'is enumerable' do
28
26
  it 'correctly uses an Enumerable method like #any?' do
29
- assert mime_types.any? { |type| type.content_type == 'text/plain' }
27
+ assert(mime_types.any? { |type| type.content_type == 'text/plain' })
30
28
  end
31
29
 
32
30
  it 'implements each with no parameters to return an Enumerator' do
@@ -95,11 +93,11 @@ describe MIME::Types do
95
93
 
96
94
  describe '#add' do
97
95
  let(:eruby) { MIME::Type.new('application/x-eruby') }
98
- let(:jinja) { MIME::Type.new('application/jinja2' )}
96
+ let(:jinja) { MIME::Type.new('application/jinja2') }
99
97
 
100
98
  it 'successfully adds a new type' do
101
99
  mime_types.add(eruby)
102
- assert_equal mime_types['application/x-eruby'], [ eruby ]
100
+ assert_equal mime_types['application/x-eruby'], [eruby]
103
101
  end
104
102
 
105
103
  it 'complains about adding a duplicate type' do
@@ -115,13 +113,13 @@ describe MIME::Types do
115
113
  assert_output '', '' do
116
114
  mime_types.add(eruby, :silent)
117
115
  end
118
- assert_equal mime_types['application/x-eruby'], [ eruby ]
116
+ assert_equal mime_types['application/x-eruby'], [eruby]
119
117
  end
120
118
 
121
119
  it 'successfully adds from an array' do
122
- mime_types.add([ eruby, jinja ])
123
- assert_equal mime_types['application/x-eruby'], [ eruby ]
124
- assert_equal mime_types['application/jinja2'], [ jinja ]
120
+ mime_types.add([eruby, jinja])
121
+ assert_equal mime_types['application/x-eruby'], [eruby]
122
+ assert_equal mime_types['application/jinja2'], [jinja]
125
123
  end
126
124
 
127
125
  it 'successfully adds from another MIME::Types' do
@@ -130,7 +128,7 @@ describe MIME::Types do
130
128
  assert_equal mime_types.count, mt.count
131
129
 
132
130
  mime_types.each do |type|
133
- assert_equal mt[type.content_type], [ type ]
131
+ assert_equal mt[type.content_type], [type]
134
132
  end
135
133
  end
136
134
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby encoding: utf-8 -*-
4
-
5
3
  require 'mime/types'
6
4
  require 'minitest_helper'
7
5
 
@@ -69,7 +67,7 @@ describe MIME::Types::Cache do
69
67
  it 'outputs an error when there is a marshal file incompatibility' do
70
68
  MIME::Types::Cache.save
71
69
  data = File.binread(@cache_file).reverse
72
- File.open(@cache_file, 'wb') { |f| f.write(data) }
70
+ File.open(@cache_file, 'wb') do |f| f.write(data) end
73
71
  MIME::Types.instance_variable_set(:@__types__, nil)
74
72
  assert_output '', /incompatible marshal file format/ do
75
73
  MIME::Types['text/html']
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby encoding: utf-8 -*-
4
-
5
3
  require 'mime/types'
6
4
  require 'minitest_helper'
7
5
 
@@ -12,7 +10,7 @@ describe MIME::Types, 'registry' do
12
10
 
13
11
  describe 'is enumerable' do
14
12
  it 'correctly uses an Enumerable method like #any?' do
15
- assert MIME::Types.any? { |type| type.content_type == 'text/plain' }
13
+ assert(MIME::Types.any? { |type| type.content_type == 'text/plain' })
16
14
  end
17
15
 
18
16
  it 'implements each with no parameters to return an Enumerator' do
@@ -45,7 +43,7 @@ describe MIME::Types, 'registry' do
45
43
 
46
44
  it 'sorts by priority with multiple matches' do
47
45
  types = MIME::Types[/gzip$/].select { |t|
48
- t == 'application/gzip' || t == 'application/x-gzip' || t == 'multipart/x-gzip'
46
+ %w(application/gzip application/x-gzip multipart/x-gzip).include?(t)
49
47
  }
50
48
  # This is this way because of a new type ending with gzip that only
51
49
  # appears in some data files.
@@ -117,11 +115,11 @@ describe MIME::Types, 'registry' do
117
115
  end
118
116
 
119
117
  let(:eruby) { MIME::Type.new('application/x-eruby') }
120
- let(:jinja) { MIME::Type.new('application/jinja2' )}
118
+ let(:jinja) { MIME::Type.new('application/jinja2') }
121
119
 
122
120
  it 'successfully adds a new type' do
123
121
  MIME::Types.add(eruby)
124
- assert_equal MIME::Types['application/x-eruby'], [ eruby ]
122
+ assert_equal MIME::Types['application/x-eruby'], [eruby]
125
123
  end
126
124
 
127
125
  it 'complains about adding a duplicate type' do
@@ -137,13 +135,13 @@ describe MIME::Types, 'registry' do
137
135
  assert_silent do
138
136
  MIME::Types.add(eruby, :silent)
139
137
  end
140
- assert_equal MIME::Types['application/x-eruby'], [ eruby ]
138
+ assert_equal MIME::Types['application/x-eruby'], [eruby]
141
139
  end
142
140
 
143
141
  it 'successfully adds from an array' do
144
- MIME::Types.add([ eruby, jinja ])
145
- assert_equal MIME::Types['application/x-eruby'], [ eruby ]
146
- assert_equal MIME::Types['application/jinja2'], [ jinja ]
142
+ MIME::Types.add([eruby, jinja])
143
+ assert_equal MIME::Types['application/x-eruby'], [eruby]
144
+ assert_equal MIME::Types['application/jinja2'], [jinja]
147
145
  end
148
146
 
149
147
  it 'successfully adds from another MIME::Types' do
@@ -155,7 +153,7 @@ describe MIME::Types, 'registry' do
155
153
  MIME::Types.add(mt)
156
154
  assert_equal old_count + 1, MIME::Types.count
157
155
 
158
- assert_equal MIME::Types[eruby.content_type], [ eruby ]
156
+ assert_equal MIME::Types[eruby.content_type], [eruby]
159
157
  end
160
158
  end
161
159
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby encoding: utf-8 -*-
4
-
5
3
  require 'mime/types'
6
4
  require 'minitest_helper'
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby encoding: utf-8 -*-
4
-
5
3
  require 'mime/types'
6
4
  require 'minitest_helper'
7
5
 
@@ -18,7 +16,7 @@ describe MIME::Types::Loader do
18
16
  refute(types['audio/webm'].first.registered?)
19
17
 
20
18
  assert_equal('Fixes a bug with IE6 and progressive JPEGs',
21
- types['image/pjpeg'].first.docs)
19
+ types['image/pjpeg'].first.docs)
22
20
 
23
21
  assert(types['audio/vnd.qcelp'].first.obsolete?)
24
22
  assert_equal('audio/QCELP', types['audio/vnd.qcelp'].first.use_instead)
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: 3.2.2
4
+ version: '3.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Ziegler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-13 00:00:00.000000000 Z
11
+ date: 2019-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types-data
@@ -235,7 +235,7 @@ dependencies:
235
235
  version: '4.0'
236
236
  - - "<"
237
237
  - !ruby/object:Gem::Version
238
- version: '6'
238
+ version: '7'
239
239
  type: :development
240
240
  prerelease: false
241
241
  version_requirements: !ruby/object:Gem::Requirement
@@ -245,21 +245,21 @@ dependencies:
245
245
  version: '4.0'
246
246
  - - "<"
247
247
  - !ruby/object:Gem::Version
248
- version: '6'
248
+ version: '7'
249
249
  - !ruby/object:Gem::Dependency
250
250
  name: hoe
251
251
  requirement: !ruby/object:Gem::Requirement
252
252
  requirements:
253
253
  - - "~>"
254
254
  - !ruby/object:Gem::Version
255
- version: '3.17'
255
+ version: '3.18'
256
256
  type: :development
257
257
  prerelease: false
258
258
  version_requirements: !ruby/object:Gem::Requirement
259
259
  requirements:
260
260
  - - "~>"
261
261
  - !ruby/object:Gem::Version
262
- version: '3.17'
262
+ version: '3.18'
263
263
  description: |-
264
264
  The mime-types library provides a library and registry for information about
265
265
  MIME content type definitions. It can be used to determine defined filename
@@ -337,8 +337,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
337
337
  - !ruby/object:Gem::Version
338
338
  version: '0'
339
339
  requirements: []
340
- rubyforge_project:
341
- rubygems_version: 2.7.7
340
+ rubygems_version: 3.0.3
342
341
  signing_key:
343
342
  specification_version: 4
344
343
  summary: The mime-types library provides a library and registry for information about