mime-types 3.3.1 → 3.7.0

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.
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ module MIME
5
+ class Types
6
+ # The released version of the mime-types library.
7
+ VERSION = "3.7.0"
8
+ end
9
+
10
+ class Type
11
+ # The released version of the mime-types library.
12
+ VERSION = MIME::Types::VERSION
13
+ end
14
+ end
data/lib/mime/types.rb CHANGED
@@ -7,7 +7,7 @@ module MIME
7
7
  end
8
8
  end
9
9
 
10
- require 'mime/type'
10
+ require "mime/type"
11
11
 
12
12
  # MIME::Types is a registry of MIME types. It is both a class (created with
13
13
  # MIME::Types.new) and a default registry (loaded automatically or through
@@ -61,19 +61,17 @@ require 'mime/type'
61
61
  # puts plaintext.ascii? # => true
62
62
  # puts plaintext.obsolete? # => false
63
63
  # puts plaintext.registered? # => true
64
+ # puts plaintext.provisional? # => false
64
65
  # puts plaintext == 'text/plain' # => true
65
66
  # puts MIME::Type.simplified('x-appl/x-zip') # => 'appl/zip'
66
67
  #
67
68
  class MIME::Types
68
- # The release version of Ruby MIME::Types
69
- VERSION = MIME::Type::VERSION
70
-
71
69
  include Enumerable
72
70
 
73
71
  # Creates a new MIME::Types registry.
74
72
  def initialize
75
- @type_variants = Container.new
76
- @extension_index = Container.new
73
+ @type_variants = Container.new
74
+ @extension_index = Container.new
77
75
  end
78
76
 
79
77
  # Returns the number of known type variants.
@@ -122,18 +120,17 @@ class MIME::Types
122
120
  # 5. Obsolete definitions use-instead clauses are compared.
123
121
  # 6. Sort on name.
124
122
  def [](type_id, complete: false, registered: false)
125
- matches = case type_id
126
- when MIME::Type
127
- @type_variants[type_id.simplified]
128
- when Regexp
129
- match(type_id)
130
- else
131
- @type_variants[MIME::Type.simplified(type_id)]
132
- end
133
-
134
- prune_matches(matches, complete, registered).sort { |a, b|
135
- a.priority_compare(b)
136
- }
123
+ matches =
124
+ case type_id
125
+ when MIME::Type
126
+ @type_variants[type_id.simplified]
127
+ when Regexp
128
+ match(type_id)
129
+ else
130
+ @type_variants[MIME::Type.simplified(type_id)]
131
+ end
132
+
133
+ prune_matches(matches, complete, registered).sort
137
134
  end
138
135
 
139
136
  # Return the list of MIME::Types which belongs to the file based on its
@@ -149,13 +146,17 @@ class MIME::Types
149
146
  # puts MIME::Types.type_for(%w(citydesk.xml citydesk.gif))
150
147
  # => [application/xml, image/gif, text/xml]
151
148
  def type_for(filename)
152
- Array(filename).flat_map { |fn|
153
- @extension_index[fn.chomp.downcase[/\.?([^.]*?)$/, 1]]
154
- }.compact.inject(Set.new, :+).sort { |a, b|
155
- a.priority_compare(b)
149
+ wanted = Array(filename).map { |fn| fn.chomp.downcase[/\.?([^.]*?)\z/m, 1] }
150
+
151
+ wanted
152
+ .flat_map { |ext| @extension_index[ext] }
153
+ .compact
154
+ .reduce(Set.new, :+)
155
+ .sort { |a, b|
156
+ a.__extension_priority_compare(b, wanted)
156
157
  }
157
158
  end
158
- alias of type_for
159
+ alias_method :of, :type_for
159
160
 
160
161
  # Add one or more MIME::Type objects to the set of known types. If the
161
162
  # type is already known, a warning will be displayed.
@@ -163,7 +164,7 @@ class MIME::Types
163
164
  # The last parameter may be the value <tt>:silent</tt> or +true+ which
164
165
  # will suppress duplicate MIME type warnings.
165
166
  def add(*types)
166
- quiet = ((types.last == :silent) or (types.last == true))
167
+ quiet = (types.last == :silent) || (types.last == true)
167
168
 
168
169
  types.each do |mime_type|
169
170
  case mime_type
@@ -184,9 +185,9 @@ class MIME::Types
184
185
  # already known, a warning will be displayed. The +quiet+ parameter may be a
185
186
  # truthy value to suppress that warning.
186
187
  def add_type(type, quiet = false)
187
- if !quiet and @type_variants[type.simplified].include?(type)
188
- MIME::Types.logger.warn <<-WARNING
189
- Type #{type} is already registered as a variant of #{type.simplified}.
188
+ if !quiet && @type_variants[type.simplified].include?(type)
189
+ MIME::Types.logger.debug <<-WARNING.chomp.strip
190
+ Type #{type} is already registered as a variant of #{type.simplified}.
190
191
  WARNING
191
192
  end
192
193
 
@@ -194,6 +195,10 @@ Type #{type} is already registered as a variant of #{type.simplified}.
194
195
  index_extensions!(type)
195
196
  end
196
197
 
198
+ def __fully_loaded? # :nodoc:
199
+ true
200
+ end
201
+
197
202
  private
198
203
 
199
204
  def add_type_variant!(mime_type)
@@ -221,11 +226,18 @@ Type #{type} is already registered as a variant of #{type.simplified}.
221
226
  k =~ pattern
222
227
  }.values.inject(Set.new, :+)
223
228
  end
229
+
230
+ # def stable_sort(list)
231
+ # list.lazy.each_with_index.sort { |(a, ai), (b, bi)|
232
+ # a.priority_compare(b).nonzero? || ai <=> bi
233
+ # }.map(&:first)
234
+ # end
224
235
  end
225
236
 
226
- require 'mime/types/cache'
227
- require 'mime/types/container'
228
- require 'mime/types/loader'
229
- require 'mime/types/logger'
230
- require 'mime/types/_columnar'
231
- require 'mime/types/registry'
237
+ require "mime/types/cache"
238
+ require "mime/types/container"
239
+ require "mime/types/loader"
240
+ require "mime/types/logger"
241
+ require "mime/types/_columnar"
242
+ require "mime/types/registry"
243
+ require "mime/types/version"
data/lib/mime-types.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mime/types'
3
+ require "mime/types"
@@ -1,13 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mime/type'
4
- require 'fileutils'
3
+ gem "minitest"
4
+ require "minitest/focus"
5
+ require "minitest/hooks"
5
6
 
6
- gem 'minitest'
7
- require 'fivemat/minitest/autorun'
8
- require 'minitest/focus'
9
- require 'minitest/rg'
10
- require 'minitest-bonus-assertions'
11
- require 'minitest/hooks'
7
+ require "fileutils"
12
8
 
13
- ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'yes'
9
+ require "mime/type"
10
+ ENV["RUBY_MIME_TYPES_LAZY_LOAD"] = "yes"