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.
data/Rakefile CHANGED
@@ -1,109 +1,102 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubygems'
4
- require 'hoe'
5
- require 'rake/clean'
6
-
7
- Hoe.plugin :doofus
8
- Hoe.plugin :gemspec2
9
- Hoe.plugin :git
10
- Hoe.plugin :minitest
11
- Hoe.plugin :travis
12
- Hoe.plugin :email unless ENV['CI'] or ENV['TRAVIS']
13
-
14
- spec = Hoe.spec 'mime-types' do
15
- developer('Austin Ziegler', 'halostatue@gmail.com')
16
- self.need_tar = true
17
-
18
- require_ruby_version '>= 2.0'
19
-
20
- self.history_file = 'History.md'
21
- self.readme_file = 'README.rdoc'
22
-
23
- license 'MIT'
24
-
25
- extra_deps << ['mime-types-data', '~> 3.2015']
26
-
27
- extra_dev_deps << ['hoe-doofus', '~> 1.0']
28
- extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
29
- extra_dev_deps << ['hoe-git', '~> 1.6']
30
- extra_dev_deps << ['hoe-rubygems', '~> 1.0']
31
- extra_dev_deps << ['hoe-travis', '~> 1.2']
32
- extra_dev_deps << ['minitest', '~> 5.4']
33
- extra_dev_deps << ['minitest-autotest', '~> 1.0']
34
- extra_dev_deps << ['minitest-focus', '~> 1.0']
35
- extra_dev_deps << ['minitest-bonus-assertions', '~> 3.0']
36
- extra_dev_deps << ['minitest-hooks', '~> 1.4']
37
- extra_dev_deps << ['rake', '>= 10.0', '< 13.0']
38
- extra_dev_deps << ['fivemat', '~> 1.3']
39
- extra_dev_deps << ['minitest-rg', '~> 5.2']
40
-
41
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.0')
42
- extra_dev_deps << ['simplecov', '~> 0.7']
43
- # if ENV['CI'] or ENV['TRAVIS']
44
- # extra_dev_deps << ['coveralls', '~> 0.8']
45
- # end
46
- end
1
+ require "rubygems"
2
+ require "hoe"
3
+ require "rake/clean"
4
+ require "minitest"
5
+ require "minitest/test_task"
6
+
7
+ Hoe.plugin :halostatue
8
+ Hoe.plugin :rubygems
9
+
10
+ Hoe.plugins.delete :debug
11
+ Hoe.plugins.delete :newb
12
+ Hoe.plugins.delete :publish
13
+ Hoe.plugins.delete :signing
14
+ Hoe.plugins.delete :test
15
+
16
+ spec = Hoe.spec "mime-types" do
17
+ developer("Austin Ziegler", "halostatue@gmail.com")
18
+
19
+ self.trusted_release = ENV["rubygems_release_gem"] == "true"
20
+
21
+ require_ruby_version ">= 2.0"
22
+
23
+ license "MIT"
24
+
25
+ spec_extras[:metadata] = ->(val) {
26
+ val.merge!({"rubygems_mfa_required" => "true"})
27
+ }
28
+
29
+ extra_deps << ["mime-types-data", "~> 3.2025", ">= 3.2025.0507"]
30
+ extra_deps << ["logger", ">= 0"]
31
+
32
+ extra_dev_deps << ["hoe", "~> 4.0"]
33
+ extra_dev_deps << ["hoe-halostatue", "~> 2.0"]
34
+ extra_dev_deps << ["hoe-rubygems", "~> 1.0"]
35
+ extra_dev_deps << ["minitest", "~> 5.0"]
36
+ extra_dev_deps << ["minitest-autotest", "~> 1.0"]
37
+ extra_dev_deps << ["minitest-focus", "~> 1.0"]
38
+ extra_dev_deps << ["minitest-hooks", "~> 1.4"]
39
+ extra_dev_deps << ["rake", ">= 10.0", "< 14"]
40
+ extra_dev_deps << ["rdoc", ">= 0.0"]
41
+ extra_dev_deps << ["standard", "~> 1.0"]
42
+ end
43
+
44
+ Minitest::TestTask.create :test
45
+ Minitest::TestTask.create :coverage do |t|
46
+ formatters = <<-RUBY.split($/).join(" ")
47
+ SimpleCov::Formatter::MultiFormatter.new([
48
+ SimpleCov::Formatter::HTMLFormatter,
49
+ SimpleCov::Formatter::LcovFormatter,
50
+ SimpleCov::Formatter::SimpleFormatter
51
+ ])
52
+ RUBY
53
+ t.test_prelude = <<-RUBY.split($/).join("; ")
54
+ require "simplecov"
55
+ require "simplecov-lcov"
56
+
57
+ SimpleCov::Formatter::LcovFormatter.config do |config|
58
+ config.report_with_single_file = true
59
+ config.lcov_file_name = "lcov.info"
60
+ end
61
+
62
+ SimpleCov.start "test_frameworks" do
63
+ enable_coverage :branch
64
+ primary_coverage :branch
65
+ formatter #{formatters}
66
+ end
67
+ RUBY
47
68
  end
48
69
 
70
+ task default: :test
71
+
49
72
  namespace :benchmark do
50
73
  task :support do
51
- %w(lib support).each { |path|
74
+ %w[lib support].each { |path|
52
75
  $LOAD_PATH.unshift(File.join(Rake.application.original_dir, path))
53
76
  }
54
77
  end
55
78
 
56
- desc 'Benchmark Load Times'
57
- task :load, [:repeats] => 'benchmark:support' do |_, args|
58
- require 'benchmarks/load'
79
+ desc "Benchmark Load Times"
80
+ task :load, [:repeats] => "benchmark:support" do |_, args|
81
+ require "benchmarks/load"
59
82
  Benchmarks::Load.report(
60
- File.join(Rake.application.original_dir, 'lib'),
83
+ File.join(Rake.application.original_dir, "lib"),
61
84
  args.repeats
62
85
  )
63
86
  end
64
87
 
65
- desc 'Allocation counts'
66
- task :allocations, [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
67
- require 'benchmarks/load_allocations'
68
- Benchmarks::LoadAllocations.report(
69
- top_x: args.top_x,
70
- mime_types_only: args.mime_types_only
71
- )
72
- end
73
-
74
- desc 'Columnar allocation counts'
75
- task 'allocations:columnar', [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
76
- require 'benchmarks/load_allocations'
77
- Benchmarks::LoadAllocations.report(
78
- columnar: true,
79
- top_x: args.top_x,
80
- mime_types_only: args.mime_types_only
81
- )
82
- end
83
-
84
- desc 'Columnar allocation counts (full load)'
85
- task 'allocations:columnar:full', [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
86
- require 'benchmarks/load_allocations'
87
- Benchmarks::LoadAllocations.report(
88
- columnar: true,
89
- top_x: args.top_x,
90
- mime_types_only: args.mime_types_only,
91
- full: true
92
- )
93
- end
94
-
95
- desc 'Memory profiler'
96
- task :memory, [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
97
- require 'benchmarks/memory_profiler'
88
+ desc "Memory profiler"
89
+ task :memory, [:top_x, :mime_types_only] => "benchmark:support" do |_, args|
90
+ require "benchmarks/profile_memory"
98
91
  Benchmarks::ProfileMemory.report(
99
92
  mime_types_only: args.mime_types_only,
100
93
  top_x: args.top_x
101
94
  )
102
95
  end
103
96
 
104
- desc 'Columnar memory profiler'
105
- task 'memory:columnar', [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
106
- require 'benchmarks/memory_profiler'
97
+ desc "Columnar memory profiler"
98
+ task "memory:columnar", [:top_x, :mime_types_only] => "benchmark:support" do |_, args|
99
+ require "benchmarks/profile_memory"
107
100
  Benchmarks::ProfileMemory.report(
108
101
  columnar: true,
109
102
  mime_types_only: args.mime_types_only,
@@ -111,9 +104,9 @@ namespace :benchmark do
111
104
  )
112
105
  end
113
106
 
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'
107
+ desc "Columnar allocation counts (full load)"
108
+ task "memory:columnar:full", [:top_x, :mime_types_only] => "benchmark:support" do |_, args|
109
+ require "benchmarks/profile_memory"
117
110
  Benchmarks::ProfileMemory.report(
118
111
  columnar: true,
119
112
  full: true,
@@ -122,111 +115,57 @@ namespace :benchmark do
122
115
  )
123
116
  end
124
117
 
125
- desc 'Object counts'
126
- task objects: 'benchmark:support' do
127
- require 'benchmarks/object_counts'
118
+ desc "Object counts"
119
+ task objects: "benchmark:support" do
120
+ require "benchmarks/object_counts"
128
121
  Benchmarks::ObjectCounts.report
129
122
  end
130
123
 
131
- desc 'Columnar object counts'
132
- task 'objects:columnar' => 'benchmark:support' do
133
- require 'benchmarks/object_counts'
124
+ desc "Columnar object counts"
125
+ task "objects:columnar" => "benchmark:support" do
126
+ require "benchmarks/object_counts"
134
127
  Benchmarks::ObjectCounts.report(columnar: true)
135
128
  end
136
129
 
137
- desc 'Columnar object counts (full load)'
138
- task 'objects:columnar:full' => 'benchmark:support' do
139
- require 'benchmarks/object_counts'
130
+ desc "Columnar object counts (full load)"
131
+ task "objects:columnar:full" => "benchmark:support" do
132
+ require "benchmarks/object_counts"
140
133
  Benchmarks::ObjectCounts.report(columnar: true, full: true)
141
134
  end
142
135
  end
143
136
 
144
137
  namespace :profile do
145
- directory 'tmp/profile'
146
-
147
- CLEAN.add 'tmp'
148
-
149
- def ruby_prof(script)
150
- require 'pathname'
151
- output = Pathname('tmp/profile').join(script)
152
- output.mkpath
153
- script = Pathname('support/profile').join("#{script}.rb")
154
-
155
- args = [
156
- '-W0',
157
- '-Ilib',
158
- '-S', 'ruby-prof',
159
- '-R', 'mime/types',
160
- '-s', 'self',
161
- '-p', 'multi',
162
- '-f', output.to_s,
163
- script.to_s
164
- ]
165
- ruby args.join(' ')
166
- end
167
-
168
- task full: 'tmp/profile' do
169
- ruby_prof 'full'
138
+ task full: "benchmark:support" do
139
+ require "profile"
140
+ profile_full
170
141
  end
171
142
 
172
- task columnar: :support do
173
- ruby_prof 'columnar'
143
+ task columnar: "benchmark:support" do
144
+ require "profile"
145
+ profile_columnar
174
146
  end
175
147
 
176
- task 'columnar:full' => :support do
177
- ruby_prof 'columnar_full'
178
- end
179
- end
180
-
181
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.0')
182
- namespace :test do
183
- # Coveralls needs to be disabled for now because it transitively depends on
184
- # an earlier version of mime-types.
185
- # if ENV['CI'] or ENV['TRAVIS']
186
- # task :coveralls do
187
- # spec.test_prelude = [
188
- # 'require "psych"',
189
- # 'require "simplecov"',
190
- # 'require "coveralls"',
191
- # 'SimpleCov.formatter = Coveralls::SimpleCov::Formatter',
192
- # 'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
193
- # 'gem "minitest"'
194
- # ].join('; ')
195
- # Rake::Task['test'].execute
196
- # end
197
-
198
- # Rake::Task['travis'].prerequisites.replace(%w(test:coveralls))
199
- # end
200
-
201
- desc 'Run test coverage'
202
- task :coverage do
203
- spec.test_prelude = [
204
- 'require "simplecov"',
205
- 'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
206
- 'gem "minitest"'
207
- ].join('; ')
208
- Rake::Task['test'].execute
209
- end
148
+ task "columnar:full" => "benchmark:support" do
149
+ require "profile"
150
+ profile_columnar_full
210
151
  end
211
152
  end
212
153
 
213
154
  namespace :convert do
214
155
  namespace :docs do
215
156
  task :setup do
216
- gem 'rdoc'
217
- require 'rdoc/rdoc'
157
+ gem "rdoc"
158
+ require "rdoc/rdoc"
218
159
  @doc_converter ||= RDoc::Markup::ToMarkdown.new
219
160
  end
220
161
 
221
- FileList['*.rdoc'].each do |name|
162
+ FileList["*.rdoc"].each do |name|
222
163
  rdoc = name
223
- mark = "#{File.basename(name, '.rdoc')}.md"
164
+ mark = "#{File.basename(name, ".rdoc")}.md"
224
165
 
225
166
  file mark => [rdoc, :setup] do |t|
226
167
  puts "#{rdoc} => #{mark}"
227
- File.open(t.name, 'wb') { |target|
228
- target.write @doc_converter.convert(IO.read(t.prerequisites.first))
229
- }
168
+ File.binwrite(t.name, @doc_converter.convert(IO.read(t.prerequisites.first)))
230
169
  end
231
170
 
232
171
  CLEAN.add mark
@@ -235,50 +174,28 @@ namespace :convert do
235
174
  end
236
175
  end
237
176
 
238
- desc 'Convert documentation from RDoc to Markdown'
239
- task docs: 'convert:docs:run'
177
+ desc "Convert documentation from RDoc to Markdown"
178
+ task docs: "convert:docs:run"
240
179
  end
241
180
 
242
- task 'deps:top', [:number] do |_, args|
243
- require 'net/http'
244
- require 'json'
245
-
246
- def rubygems_get(gem_name: '', endpoint: '')
247
- path = File.join('/api/v1/gems/', gem_name, endpoint).chomp('/') + '.json'
248
- Net::HTTP.start('rubygems.org', use_ssl: true) do |http|
249
- JSON.parse(http.get(path).body)
250
- end
251
- end
252
-
253
- results = rubygems_get(
254
- gem_name: 'mime-types',
255
- endpoint: 'reverse_dependencies'
256
- )
257
-
258
- weighted_results = {}
259
- results.each do |name|
260
- begin
261
- weighted_results[name] = rubygems_get(gem_name: name)['downloads']
262
- rescue => e
263
- puts "#{name} #{e.message}"
264
- end
265
- end
181
+ task :version do
182
+ require "mime/types/version"
183
+ puts MIME::Types::VERSION
184
+ end
266
185
 
267
- weighted_results.sort { |(_k1, v1), (_k2, v2)|
268
- v2 <=> v1
269
- }.first(args.number || 50).each_with_index do |(k, v), i|
270
- puts "#{i}) #{k}: #{v}"
186
+ namespace :deps do
187
+ task :top, [:number] => "benchmark:support" do |_, args|
188
+ require "deps"
189
+ Deps.run(args)
271
190
  end
272
191
  end
273
192
 
274
193
  task :console do
275
- arguments = %w(pry)
194
+ arguments = %w[irb]
276
195
  arguments.push(*spec.spec.require_paths.map { |dir| "-I#{dir}" })
277
- arguments.push("-r#{spec.spec.name.gsub('-', File::SEPARATOR)}")
196
+ arguments.push("-r#{spec.spec.name.gsub("-", File::SEPARATOR)}")
278
197
  unless system(*arguments)
279
198
  error "Command failed: #{show_command}"
280
199
  abort
281
200
  end
282
201
  end
283
-
284
- # vim: syntax=ruby
data/SECURITY.md ADDED
@@ -0,0 +1,7 @@
1
+ # mime-types Security
2
+
3
+ ## Security contact information
4
+
5
+ To report a security vulnerability, please use the
6
+ [Tidelift security contact](https://tidelift.com/security). Tidelift will
7
+ coordinate the fix and disclosure.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mime/type'
3
+ require "mime/type"
4
4
 
5
5
  # A version of MIME::Type that works hand-in-hand with a MIME::Types::Columnar
6
6
  # container to load data by columns.
@@ -15,8 +15,10 @@ require 'mime/type'
15
15
  class MIME::Type::Columnar < MIME::Type
16
16
  def initialize(container, content_type, extensions) # :nodoc:
17
17
  @container = container
18
+ @__priority_penalty = nil
18
19
  self.content_type = content_type
19
- self.extensions = extensions
20
+ @extensions = Set[*Array(extensions).flatten.compact].freeze
21
+ clear_sort_priority
20
22
  end
21
23
 
22
24
  def self.column(*methods, file: nil) # :nodoc:
@@ -35,8 +37,8 @@ class MIME::Type::Columnar < MIME::Type
35
37
  column :encoding, :encoding=
36
38
  column :docs, :docs=
37
39
  column :preferred_extension, :preferred_extension=
38
- column :obsolete, :obsolete=, :obsolete?, :registered, :registered=,
39
- :registered?, :signature, :signature=, :signature?, file: 'flags'
40
+ column :obsolete, :obsolete=, :obsolete?, :registered, :registered=, :registered?, :signature, :signature=,
41
+ :signature?, :provisional, :provisional=, :provisional?, file: "flags"
40
42
  column :xrefs, :xrefs=, :xref_urls
41
43
  column :use_instead, :use_instead=
42
44
 
@@ -51,6 +53,17 @@ class MIME::Type::Columnar < MIME::Type
51
53
  super
52
54
  end
53
55
 
56
+ def update_sort_priority
57
+ if @container.__fully_loaded?
58
+ super
59
+ else
60
+ obsolete = (@__sort_priority & (1 << 7)) != 0
61
+ registered = (@__sort_priority & (1 << 5)) == 0
62
+
63
+ @__priority_penalty = (obsolete ? 3 : 0) + (registered ? 0 : 2)
64
+ end
65
+ end
66
+
54
67
  class << self
55
68
  undef column
56
69
  end