mime-types 3.0 → 3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7023816dbfc18473c51bed6f14864322167273fe
4
- data.tar.gz: d29e9c15601cca71c991bc5cc1b50b31c1864d74
3
+ metadata.gz: 11704604d6f6c628181b2032710b540aae28c9ec
4
+ data.tar.gz: 0df4d307401973b49924d6e08211b40c874eb7e9
5
5
  SHA512:
6
- metadata.gz: 1e7ba49d9b78b1331085a956c9c4c6c24687e7f69443bc00370b4e233874d32d28067d9171d50d14b14ea2bd4885a9b452b6ccc0a1fd179283855aebf9a23a3d
7
- data.tar.gz: 7aa2a2ff6b297ed18a4feb6029d30b051fcc87bcd6d7aa6be37be3b9caa15e4207756614c729322e62592ae71abc5beeafbae40959194719fb11ac8acbfde2d9
6
+ metadata.gz: c18fed9452a57c1b4123bc7e476baa845f1690b83fa26d07ac87a27bb1168b138fbf2bfdce49424f307069ade0216e2f437f10bb0f5c3fe3245965161514dd90
7
+ data.tar.gz: 7f704ed00215197e047d5b8155a87489bf066c35e94ac7034eb548dd53bec6f5038e9bf67cc160affc59114aab87391a7f1abcb4a9c328d864c366ad40a96c37
@@ -1,41 +1,74 @@
1
- == Contributor Code of Conduct
1
+ == Contributor Covenant Code of Conduct
2
2
 
3
- As contributors and maintainers of this project, and in the interest of
4
- fostering an open and welcoming community, we pledge to respect all people who
5
- contribute through reporting issues, posting feature requests, updating
6
- documentation, submitting pull requests or patches, and other activities.
3
+ ## Our Pledge
7
4
 
8
- We are committed to making participation in this project a harassment-free
9
- experience for everyone, regardless of level of experience, gender, gender
10
- identity and expression, sexual orientation, disability, personal appearance,
11
- body size, race, ethnicity, age, religion, or nationality.
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age,
8
+ body size, disability, ethnicity, gender identity and expression, level of
9
+ experience, nationality, personal appearance, race, religion, or sexual
10
+ identity and orientation.
11
+
12
+ === Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
12
22
 
13
23
  Examples of unacceptable behavior by participants include:
14
24
 
15
- * The use of sexualized language or imagery
16
- * Personal attacks
17
- * Trolling or insulting/derogatory comments
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
18
28
  * Public or private harassment
19
- * Publishing other's private information, such as physical or electronic
20
- addresses, without explicit permission
21
- * Other unethical or unprofessional conduct.
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ === Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
22
39
 
23
40
  Project maintainers have the right and responsibility to remove, edit, or
24
41
  reject comments, commits, code, wiki edits, issues, and other contributions
25
- that are not aligned to this Code of Conduct. By adopting this Code of Conduct,
26
- project maintainers commit themselves to fairly and consistently applying these
27
- principles to every aspect of managing this project. Project maintainers who do
28
- not follow or enforce the Code of Conduct may be permanently removed from the
29
- project team.
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
30
45
 
31
- This code of conduct applies both within project spaces and in public spaces
32
- when an individual is representing the project or its community.
46
+ === Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an
52
+ appointed representative at an online or offline event. Representation of a
53
+ project may be further defined and clarified by project maintainers.
54
+
55
+ === Enforcement
33
56
 
34
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
35
- reported by opening an issue or contacting one or more of the project
36
- maintainers.
58
+ reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an
62
+ incident. Further details of specific enforcement policies may be posted
63
+ separately.
64
+
65
+ Project maintainers who do not follow or enforce the Code of Conduct in good
66
+ faith may face temporary or permanent repercussions as determined by other
67
+ members of the project's leadership.
68
+
69
+ === Attribution
37
70
 
38
- This Code of Conduct is adapted from the
39
- {Contributor Covenant}[http://contributor-covenant.org], version 1.2.0,
71
+ This Code of Conduct is adapted from the {Contributor
72
+ Covenant}[http://contributor-covenant.org], version 1.4,
40
73
  available at
41
- {http://contributor-covenant.org/version/1/2/0/}[http://contributor-covenant.org/version/1/2/0/].
74
+ {http://contributor-covenant.org/version/1/4/}[http://contributor-covenant.org/version/1/4/].
@@ -18,48 +18,9 @@ There are a few guidelines for contributing to mime-types:
18
18
 
19
19
  === Adding or Modifying MIME Types
20
20
 
21
- The mime-types registry is loaded from encoded files in +data+. These are not
22
- editable and cannot be compared meaningfully in a pull request; pull requests
23
- that include changes to these files will require amendment to revert these
24
- files.
25
-
26
- New or modified MIME types should be edited in the appropriate YAML file under
27
- +type-lists+. The format is as shown below for the +application/xml+ MIME type
28
- in +type-lists/application.yml+.
29
-
30
- - !ruby/object:MIME::Type
31
- content-type: application/xml
32
- encoding: 8bit
33
- extensions:
34
- - xml
35
- - xsl
36
- xrefs: !ruby/hash:MIME::Types::Container
37
- rfc:
38
- - rfc3023
39
- registered: true
40
-
41
- There are other fields that can be added, matching the fields discussed in the
42
- documentation for MIME::Type. Pull requests for MIME types should just contain
43
- the changes to the YAML files for the new or modified MIME types; I will
44
- convert the YAML files to JSON prior to a new release. I would rather not have
45
- to verify that the JSON matches the YAML changes, which is why it is not
46
- necessary to convert for the pull request.
47
-
48
- If you are making a change for a private fork, use <tt>rake
49
- convert:yaml:json</tt> to convert the YAML to JSON, or <tt>rake
50
- convert:yaml:columnar</tt> to convert it to the new columnar format.
51
-
52
- ==== Updating Types from the IANA or Apache Lists
53
-
54
- If you are maintaining a private fork and wish to update your copy of the MIME
55
- types registry used by this gem, you can do this with the rake tasks:
56
-
57
- $ rake mime:iana
58
- $ rake mime:apache
59
-
60
- Both of these require
61
- {Nokogiri}[http://www.nokogiri.org/tutorials/installing_nokogiri.html], which
62
- is not installed by default. Install it in the usual way for your Ruby.
21
+ The mime-types registry is no longer contained in mime-types, but in
22
+ {mime-types-data}[https://github.com/mime-types/mime-types-data]. Please see
23
+ that project for contributions there.
63
24
 
64
25
  === Test Dependencies
65
26
 
@@ -1,3 +1,32 @@
1
+ == 3.1 / 2016-05-22
2
+
3
+ * 1 documentation change:
4
+
5
+ * Tim Smith (@tas50) updated the build badges to be SVGs to improve
6
+ readability on high-density (retina) screens with pull request
7
+ {#112}[https://github.com/mime-types/ruby-mime-types/pull/112].
8
+
9
+ * 3 bug fixes
10
+
11
+ * A test for MIME::Types::Cache fails under Ruby 2.3 because of frozen
12
+ strings, {#118}[https://github.com/mime-types/ruby-mime-types/issues/118].
13
+ This has been fixed.
14
+
15
+ * The JSON data has been incorrectly encoded since the release of mime-types
16
+ 3 on the +xrefs+ field, because of the switch to using a Set to store
17
+ cross-reference information. This has been fixed.
18
+
19
+ * A tentative fix for
20
+ {#117}[https://github.com/mime-types/ruby-mime-types/issues/117] has been
21
+ applied, removing the only circular require dependencies that exist (and
22
+ for which there was code to prevent, but the current fix is simpler).
23
+ I have no way to verify this fix and depending on how things are loaded by
24
+ +delayed_job+, this fix may not be sufficient.
25
+
26
+ * 1 governance change
27
+
28
+ * Updated to {Contributor Covenant 1.4}[Code-of-Conduct_rdoc.html].
29
+
1
30
  == 3.0 / 2015-11-21
2
31
 
3
32
  * 2 governance changes
@@ -1,6 +1,6 @@
1
1
  == Licence
2
2
 
3
- * Copyright 2003–2015 Austin Ziegler.
3
+ * Copyright 2003–2015 Austin Ziegler and contributors.
4
4
 
5
5
  The software in this repository is made available under the MIT license.
6
6
 
@@ -1,7 +1,3 @@
1
- .autotest
2
- .gemtest
3
- .gitignore
4
- .hoerc
5
1
  Code-of-Conduct.rdoc
6
2
  Contributing.rdoc
7
3
  History.rdoc
@@ -13,6 +9,7 @@ lib/mime-types.rb
13
9
  lib/mime/type.rb
14
10
  lib/mime/type/columnar.rb
15
11
  lib/mime/types.rb
12
+ lib/mime/types/_columnar.rb
16
13
  lib/mime/types/cache.rb
17
14
  lib/mime/types/columnar.rb
18
15
  lib/mime/types/container.rb
@@ -21,12 +18,6 @@ lib/mime/types/full.rb
21
18
  lib/mime/types/loader.rb
22
19
  lib/mime/types/logger.rb
23
20
  lib/mime/types/registry.rb
24
- support/benchmarks/load.rb
25
- support/benchmarks/load_allocations.rb
26
- support/benchmarks/object_counts.rb
27
- support/profile/columnar.rb
28
- support/profile/columnar_full.rb
29
- support/profile/full.rb
30
21
  test/bad-fixtures/malformed
31
22
  test/fixture/json.json
32
23
  test/fixture/old-data
@@ -4,8 +4,8 @@ home :: https://github.com/mime-types/ruby-mime-types/
4
4
  code :: https://github.com/mime-types/ruby-mime-types/
5
5
  bugs :: https://github.com/mime-types/ruby-mime-types/issues
6
6
  rdoc :: http://rdoc.info/gems/mime-types/
7
- continuous integration :: {<img src="https://travis-ci.org/mime-types/ruby-mime-types.png" />}[https://travis-ci.org/mime-types/ruby-mime-types]
8
- test coverage :: {<img src="https://coveralls.io/repos/mime-types/ruby-mime-types/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/mime-types/ruby-mime-types]
7
+ continuous integration :: {<img src="https://travis-ci.org/mime-types/ruby-mime-types.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/mime-types/ruby-mime-types]
8
+ test coverage :: {<img src="https://coveralls.io/repos/mime-types/ruby-mime-types/badge.svg?branch=master&service=github" alt="Coverage Status" />}[https://coveralls.io/github/mime-types/ruby-mime-types?branch=master]
9
9
 
10
10
  == Description
11
11
 
@@ -83,8 +83,8 @@ files). A MIME::Type stores the known information about one MIME type.
83
83
  puts text == 'text/x-plain' # => false
84
84
  puts 'text/x-plain' == text # => false
85
85
 
86
- puts MIME::Type.simplified('x-appl/x-zip') # => 'appl/zip'
87
- puts MIME::Type.i18n_key('x-appl/x-zip') # => 'appl.zip'
86
+ puts MIME::Type.simplified('x-appl/x-zip') # => 'x-appl/x-zip'
87
+ puts MIME::Type.i18n_key('x-appl/x-zip') # => 'x-appl.x-zip'
88
88
 
89
89
  puts text.like?('text/x-plain') # => true
90
90
  puts text.like?(MIME::Type.new('x-text/x-plain')) # => true
@@ -111,7 +111,7 @@ files). A MIME::Type stores the known information about one MIME type.
111
111
 
112
112
  xwingz = MIME::Types['application/x-Wingz'].first # => application/x-Wingz
113
113
  puts xwingz.content_type # => 'application/x-Wingz'
114
- puts xwingz.simplified # => 'application/wingz'
114
+ puts xwingz.simplified # => 'application/x-wingz'
115
115
 
116
116
  === Columnar Store
117
117
 
@@ -183,19 +183,17 @@ MAJOR.MINOR:
183
183
  incremented, MINOR will be set to zero, and PATCH will be reset to the
184
184
  implied zero.
185
185
 
186
- 2. If an API (code) feature is added that does not break compatibilty OR if
187
- there are MIME types added, removed, or changed in the registry, the MINOR
188
- version will be incremented and PATCH will be reset to the implied zero.
186
+ 2. If an API (code) feature is added that does not break compatibilty, the
187
+ MINOR version will be incremented and PATCH will be reset to the implied zero.
189
188
 
190
189
  3. If there is a bugfix to a feature added in the most recent MAJOR.MINOR
191
- release, OR if purely typographical errors are fixed in MIME types, the
192
- implied PATCH value will be incremented resulting in MAJOR.MINOR.PATCH.
193
-
194
- In practical terms, there should be a MINOR release roughly monthly to track
195
- updated or changed MIME types from the official IANA registry. This does not
196
- indicate when new API features have been added, but all minor versions of
197
- mime-types 2.x will be backwards compatible; the interfaces marked deprecated
198
- will be removed in mime-types 3.x.
190
+ release, the implied PATCH value will be incremented resulting in
191
+ MAJOR.MINOR.PATCH.
192
+
193
+ In practical terms, there will be fewer releases of mime-types focussing on
194
+ features because of the existence of the [mime-types-data][] gem, and if
195
+ features are marked deprecated in the course of mime-types 3.x, they will not
196
+ be removed until mime-types 4.x or possibly later.
199
197
 
200
198
  :include: Code-of-Conduct.rdoc
201
199
 
data/Rakefile CHANGED
@@ -33,6 +33,7 @@ spec = Hoe.spec 'mime-types' do
33
33
  extra_dev_deps << ['minitest-autotest', '~> 1.0']
34
34
  extra_dev_deps << ['minitest-focus', '~> 1.0']
35
35
  extra_dev_deps << ['minitest-bonus-assertions', '~> 2.0']
36
+ extra_dev_deps << ['minitest-hooks', '~> 1.4']
36
37
  extra_dev_deps << ['rake', '~> 10.0']
37
38
  extra_dev_deps << ['fivemat', '~> 1.3' ]
38
39
  extra_dev_deps << ['minitest-rg', '~> 5.2']
@@ -188,8 +189,8 @@ namespace :convert do
188
189
  end
189
190
 
190
191
  FileList['*.rdoc'].each do |name|
191
- rdoc = "#{name}.rdoc"
192
- mark = "#{name}.md"
192
+ rdoc = name
193
+ mark = "#{File.basename(name, '.rdoc')}.md"
193
194
 
194
195
  file mark => [ rdoc, :setup ] do |t|
195
196
  puts "#{rdoc} => #{mark}"
@@ -208,6 +209,38 @@ namespace :convert do
208
209
  task docs: 'convert:docs:run'
209
210
  end
210
211
 
212
+ task 'deps:top', [ :number ] do |_, args|
213
+ require 'net/http'
214
+ require 'json'
215
+
216
+ def rubygems_get(gem_name: '', endpoint: '')
217
+ path = File.join('/api/v1/gems/', gem_name, endpoint).chomp('/') + '.json'
218
+ Net::HTTP.start('rubygems.org', use_ssl: true) do |http|
219
+ JSON.parse(http.get(path).body)
220
+ end
221
+ end
222
+
223
+ results = rubygems_get(
224
+ gem_name: 'mime-types',
225
+ endpoint: 'reverse_dependencies'
226
+ )
227
+
228
+ weighted_results = {}
229
+ results.each do |name|
230
+ begin
231
+ weighted_results[name] = rubygems_get(gem_name: name)['downloads']
232
+ rescue => e
233
+ puts "#{name} #{e.message}"
234
+ end
235
+ end
236
+
237
+ weighted_results.sort { |(_k1, v1), (_k2, v2)|
238
+ v2 <=> v1
239
+ }.first(args.number || 50).each_with_index do |(k, v), i|
240
+ puts "#{i}) #{k}: #{v}"
241
+ end
242
+ end
243
+
211
244
  task :console do
212
245
  arguments = %w(pry)
213
246
  arguments.push(*spec.spec.require_paths.map { |dir| "-I#{dir}" })
@@ -55,7 +55,7 @@ class MIME::Type
55
55
  end
56
56
 
57
57
  # The released version of the mime-types library.
58
- VERSION = '3.0'
58
+ VERSION = '3.1'
59
59
 
60
60
  include Comparable
61
61
 
@@ -450,7 +450,14 @@ class MIME::Type
450
450
  coder['obsolete'] = obsolete?
451
451
  coder['use-instead'] = use_instead if use_instead
452
452
  end
453
- coder['xrefs'] = xrefs unless xrefs.empty?
453
+ unless xrefs.empty?
454
+ {}.tap do |hash|
455
+ xrefs.each do |k, v|
456
+ hash[k] = v.sort.to_a
457
+ end
458
+ coder['xrefs'] = hash
459
+ end
460
+ end
454
461
  coder['registered'] = registered?
455
462
  coder['signature'] = signature? if signature?
456
463
  coder
@@ -5,11 +5,7 @@ module MIME
5
5
  end
6
6
  end
7
7
 
8
- require 'mime/types/logger'
9
- require 'mime/types/container'
10
8
  require 'mime/type'
11
- require 'mime/types/cache'
12
- require 'mime/types/loader'
13
9
 
14
10
  # MIME::Types is a registry of MIME types. It is both a class (created with
15
11
  # MIME::Types.new) and a default registry (loaded automatically or through
@@ -224,5 +220,9 @@ Type #{type} is already registered as a variant of #{type.simplified}.
224
220
  end
225
221
  end
226
222
 
227
- require 'mime/types/columnar' unless defined?(MIME::Types::Columnar)
223
+ require 'mime/types/cache'
224
+ require 'mime/types/container'
225
+ require 'mime/types/loader'
226
+ require 'mime/types/logger'
227
+ require 'mime/types/_columnar'
228
228
  require 'mime/types/registry'
@@ -0,0 +1,135 @@
1
+ require 'mime/type/columnar'
2
+
3
+ # MIME::Types::Columnar is used to extend a MIME::Types container to load data
4
+ # by columns instead of from JSON or YAML. Column loads of MIME types loaded
5
+ # through the columnar store are synchronized with a Mutex.
6
+ #
7
+ # MIME::Types::Columnar is not intended to be used directly, but will be added
8
+ # to an instance of MIME::Types when it is loaded with
9
+ # MIME::Types::Loader#load_columnar.
10
+ module MIME::Types::Columnar
11
+ LOAD_MUTEX = Mutex.new # :nodoc:
12
+
13
+ def self.extended(obj) # :nodoc:
14
+ super
15
+ obj.instance_variable_set(:@__mime_data__, [])
16
+ obj.instance_variable_set(:@__files__, Set.new)
17
+ end
18
+
19
+ # Load the first column data file (type and extensions).
20
+ def load_base_data(path) #:nodoc:
21
+ @__root__ = path
22
+
23
+ each_file_line('content_type', false) do |line|
24
+ line = line.split
25
+ content_type = line.shift
26
+ extensions = line
27
+ # content_type, *extensions = line.split
28
+
29
+ type = MIME::Type::Columnar.new(self, content_type, extensions)
30
+ @__mime_data__ << type
31
+ add(type)
32
+ end
33
+
34
+ self
35
+ end
36
+
37
+ private
38
+
39
+ def each_file_line(name, lookup = true)
40
+ LOAD_MUTEX.synchronize do
41
+ next if @__files__.include?(name)
42
+
43
+ i = -1
44
+ column = File.join(@__root__, "mime.#{name}.column")
45
+
46
+ IO.readlines(column, encoding: 'UTF-8'.freeze).each do |line|
47
+ line.chomp!
48
+
49
+ if lookup
50
+ type = @__mime_data__[i += 1] or next
51
+ yield type, line
52
+ else
53
+ yield line
54
+ end
55
+ end
56
+
57
+ @__files__ << name
58
+ end
59
+ end
60
+
61
+ def load_encoding
62
+ each_file_line('encoding') do |type, line|
63
+ pool ||= {}
64
+ line.freeze
65
+ type.instance_variable_set(:@encoding, (pool[line] ||= line))
66
+ end
67
+ end
68
+
69
+ def load_docs
70
+ each_file_line('docs') do |type, line|
71
+ type.instance_variable_set(:@docs, opt(line))
72
+ end
73
+ end
74
+
75
+ def load_preferred_extension
76
+ each_file_line('pext') do |type, line|
77
+ type.instance_variable_set(:@preferred_extension, opt(line))
78
+ end
79
+ end
80
+
81
+ def load_flags
82
+ each_file_line('flags') do |type, line|
83
+ line = line.split
84
+ type.instance_variable_set(:@obsolete, flag(line.shift))
85
+ type.instance_variable_set(:@registered, flag(line.shift))
86
+ type.instance_variable_set(:@signature, flag(line.shift))
87
+ end
88
+ end
89
+
90
+ def load_xrefs
91
+ each_file_line('xrefs') { |type, line|
92
+ type.instance_variable_set(:@xrefs, dict(line, array: true))
93
+ }
94
+ end
95
+
96
+ def load_friendly
97
+ each_file_line('friendly') { |type, line|
98
+ type.instance_variable_set(:@friendly, dict(line))
99
+ }
100
+ end
101
+
102
+ def load_use_instead
103
+ each_file_line('use_instead') do |type, line|
104
+ type.instance_variable_set(:@use_instead, opt(line))
105
+ end
106
+ end
107
+
108
+ def dict(line, array: false)
109
+ if line == '-'.freeze
110
+ {}
111
+ else
112
+ line.split('|'.freeze).each_with_object({}) { |l, h|
113
+ k, v = l.split('^'.freeze)
114
+ v = nil if v.empty?
115
+ h[k] = array ? Array(v) : v
116
+ }
117
+ end
118
+ end
119
+
120
+ def arr(line)
121
+ if line == '-'.freeze
122
+ []
123
+ else
124
+ line.split('|'.freeze).flatten.compact.uniq
125
+ end
126
+ end
127
+
128
+ def opt(line)
129
+ line unless line == '-'.freeze
130
+ end
131
+
132
+ def flag(line)
133
+ line == '1'.freeze ? true : false
134
+ end
135
+ end
@@ -1,142 +1 @@
1
- module MIME
2
- class Types
3
- end
4
- end
5
-
6
- require 'mime/type/columnar'
7
-
8
- # MIME::Types::Columnar is used to extend a MIME::Types container to load data
9
- # by columns instead of from JSON or YAML. Column loads of MIME types loaded
10
- # through the columnar store are synchronized with a Mutex.
11
- #
12
- # MIME::Types::Columnar is not intended to be used directly, but will be added
13
- # to an instance of MIME::Types when it is loaded with
14
- # MIME::Types::Loader#load_columnar.
15
- module MIME::Types::Columnar
16
- LOAD_MUTEX = Mutex.new # :nodoc:
17
-
18
- def self.extended(obj) # :nodoc:
19
- super
20
- obj.instance_variable_set(:@__mime_data__, [])
21
- obj.instance_variable_set(:@__files__, Set.new)
22
- end
23
-
24
- # Load the first column data file (type and extensions).
25
- def load_base_data(path) #:nodoc:
26
- @__root__ = path
27
-
28
- each_file_line('content_type', false) do |line|
29
- line = line.split
30
- content_type = line.shift
31
- extensions = line
32
- # content_type, *extensions = line.split
33
-
34
- type = MIME::Type::Columnar.new(self, content_type, extensions)
35
- @__mime_data__ << type
36
- add(type)
37
- end
38
-
39
- self
40
- end
41
-
42
- private
43
-
44
- def each_file_line(name, lookup = true)
45
- LOAD_MUTEX.synchronize do
46
- next if @__files__.include?(name)
47
-
48
- i = -1
49
- column = File.join(@__root__, "mime.#{name}.column")
50
-
51
- IO.readlines(column, encoding: 'UTF-8'.freeze).each do |line|
52
- line.chomp!
53
-
54
- if lookup
55
- type = @__mime_data__[i += 1] or next
56
- yield type, line
57
- else
58
- yield line
59
- end
60
- end
61
-
62
- @__files__ << name
63
- end
64
- end
65
-
66
- def load_encoding
67
- each_file_line('encoding') do |type, line|
68
- pool ||= {}
69
- line.freeze
70
- type.instance_variable_set(:@encoding, (pool[line] ||= line))
71
- end
72
- end
73
-
74
- def load_docs
75
- each_file_line('docs') do |type, line|
76
- type.instance_variable_set(:@docs, opt(line))
77
- end
78
- end
79
-
80
- def load_preferred_extension
81
- each_file_line('pext') do |type, line|
82
- type.instance_variable_set(:@preferred_extension, opt(line))
83
- end
84
- end
85
-
86
- def load_flags
87
- each_file_line('flags') do |type, line|
88
- line = line.split
89
- type.instance_variable_set(:@obsolete, flag(line.shift))
90
- type.instance_variable_set(:@registered, flag(line.shift))
91
- type.instance_variable_set(:@signature, flag(line.shift))
92
- end
93
- end
94
-
95
- def load_xrefs
96
- each_file_line('xrefs') { |type, line|
97
- type.instance_variable_set(:@xrefs, dict(line, array: true))
98
- }
99
- end
100
-
101
- def load_friendly
102
- each_file_line('friendly') { |type, line|
103
- type.instance_variable_set(:@friendly, dict(line))
104
- }
105
- end
106
-
107
- def load_use_instead
108
- each_file_line('use_instead') do |type, line|
109
- type.instance_variable_set(:@use_instead, opt(line))
110
- end
111
- end
112
-
113
- def dict(line, array: false)
114
- if line == '-'.freeze
115
- {}
116
- else
117
- line.split('|'.freeze).each_with_object({}) { |l, h|
118
- k, v = l.split('^'.freeze)
119
- v = nil if v.empty?
120
- h[k] = array ? Array(v) : v
121
- }
122
- end
123
- end
124
-
125
- def arr(line)
126
- if line == '-'.freeze
127
- []
128
- else
129
- line.split('|'.freeze).flatten.compact.uniq
130
- end
131
- end
132
-
133
- def opt(line)
134
- line unless line == '-'.freeze
135
- end
136
-
137
- def flag(line)
138
- line == '1'.freeze ? true : false
139
- end
140
- end
141
-
142
- require 'mime/types' unless defined?(MIME::Types::VERSION)
1
+ require 'mime/types'
@@ -10,8 +10,8 @@ module MIME
10
10
  { columnar: false }
11
11
  end
12
12
  end
13
-
14
- require 'mime/types'
15
13
  end
16
14
  end
17
15
  end
16
+
17
+ require 'mime/types'
@@ -8,5 +8,6 @@ require 'fivemat/minitest/autorun'
8
8
  require 'minitest/focus'
9
9
  require 'minitest/rg'
10
10
  require 'minitest-bonus-assertions'
11
+ require 'minitest/hooks'
11
12
 
12
13
  ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'yes'
@@ -43,7 +43,7 @@ describe MIME::Types do
43
43
  end
44
44
  end
45
45
 
46
- describe '#\[]' do
46
+ describe '#[]' do
47
47
  it 'can be searched with a MIME::Type' do
48
48
  text_plain = MIME::Type.new('text/plain')
49
49
  assert_includes mime_types[text_plain], 'text/plain'
@@ -4,16 +4,23 @@ require 'mime/types'
4
4
  require 'minitest_helper'
5
5
 
6
6
  describe MIME::Types::Cache do
7
- def setup
7
+ include Minitest::Hooks
8
+
9
+ MUTEX = Mutex.new
10
+
11
+ def around
8
12
  require 'fileutils'
9
- @cache_file = File.expand_path('../cache.tst', __FILE__)
10
- ENV['RUBY_MIME_TYPES_CACHE'] = @cache_file
11
- clear_cache_file
12
- end
13
13
 
14
- def teardown
15
- clear_cache_file
16
- ENV.delete('RUBY_MIME_TYPES_CACHE')
14
+ MUTEX.synchronize do
15
+ @cache_file = File.expand_path('../cache.tst', __FILE__)
16
+ ENV['RUBY_MIME_TYPES_CACHE'] = @cache_file
17
+ clear_cache_file
18
+
19
+ super
20
+
21
+ clear_cache_file
22
+ ENV.delete('RUBY_MIME_TYPES_CACHE')
23
+ end
17
24
  end
18
25
 
19
26
  def reset_mime_types
@@ -36,10 +43,12 @@ describe MIME::Types::Cache do
36
43
  end
37
44
 
38
45
  it 'outputs an error when there is an invalid version' do
39
- v = MIME::Types::Data::VERSION.dup
40
- MIME::Types::Data::VERSION.gsub!(/.*/, '0.0')
46
+ v = MIME::Types::Data::VERSION
47
+ MIME::Types::Data.send(:remove_const, :VERSION)
48
+ MIME::Types::Data.const_set(:VERSION, '0.0')
41
49
  MIME::Types::Cache.save
42
- MIME::Types::Data::VERSION.gsub!(/.*/, v)
50
+ MIME::Types::Data.send(:remove_const, :VERSION)
51
+ MIME::Types::Data.const_set(:VERSION, v)
43
52
  MIME::Types.instance_variable_set(:@__types__, nil)
44
53
  assert_output '', /MIME::Types cache: invalid version/ do
45
54
  MIME::Types['text/html']
@@ -29,7 +29,7 @@ describe MIME::Types, 'registry' do
29
29
  end
30
30
  end
31
31
 
32
- describe '.\[]' do
32
+ describe '.[]' do
33
33
  it 'can be searched with a MIME::Type' do
34
34
  text_plain = MIME::Type.new('text/plain')
35
35
  assert_includes MIME::Types[text_plain], 'text/plain'
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.0'
4
+ version: '3.1'
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-11-21 00:00:00.000000000 Z
11
+ date: 2016-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types-data
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.8'
33
+ version: '5.9'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.8'
40
+ version: '5.9'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '2.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: minitest-hooks
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1.4'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '1.4'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rake
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -226,14 +240,14 @@ dependencies:
226
240
  requirements:
227
241
  - - "~>"
228
242
  - !ruby/object:Gem::Version
229
- version: '3.14'
243
+ version: '3.15'
230
244
  type: :development
231
245
  prerelease: false
232
246
  version_requirements: !ruby/object:Gem::Requirement
233
247
  requirements:
234
248
  - - "~>"
235
249
  - !ruby/object:Gem::Version
236
- version: '3.14'
250
+ version: '3.15'
237
251
  description: |-
238
252
  The mime-types library provides a library and registry for information about
239
253
  MIME content type definitions. It can be used to determine defined filename
@@ -259,10 +273,6 @@ extra_rdoc_files:
259
273
  - Manifest.txt
260
274
  - README.rdoc
261
275
  files:
262
- - ".autotest"
263
- - ".gemtest"
264
- - ".gitignore"
265
- - ".hoerc"
266
276
  - Code-of-Conduct.rdoc
267
277
  - Contributing.rdoc
268
278
  - History.rdoc
@@ -274,6 +284,7 @@ files:
274
284
  - lib/mime/type.rb
275
285
  - lib/mime/type/columnar.rb
276
286
  - lib/mime/types.rb
287
+ - lib/mime/types/_columnar.rb
277
288
  - lib/mime/types/cache.rb
278
289
  - lib/mime/types/columnar.rb
279
290
  - lib/mime/types/container.rb
@@ -282,12 +293,6 @@ files:
282
293
  - lib/mime/types/loader.rb
283
294
  - lib/mime/types/logger.rb
284
295
  - lib/mime/types/registry.rb
285
- - support/benchmarks/load.rb
286
- - support/benchmarks/load_allocations.rb
287
- - support/benchmarks/object_counts.rb
288
- - support/profile/columnar.rb
289
- - support/profile/columnar_full.rb
290
- - support/profile/full.rb
291
296
  - test/bad-fixtures/malformed
292
297
  - test/fixture/json.json
293
298
  - test/fixture/old-data
@@ -321,7 +326,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
326
  version: '0'
322
327
  requirements: []
323
328
  rubyforge_project:
324
- rubygems_version: 2.4.8
329
+ rubygems_version: 2.6.4
325
330
  signing_key:
326
331
  specification_version: 4
327
332
  summary: The mime-types library provides a library and registry for information about
data/.autotest DELETED
@@ -1,35 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- require 'autotest/bundler'
4
- require 'autotest/restart'
5
- require 'autotest/timestamp'
6
-
7
- def require_plugin(resource)
8
- require resource
9
- rescue LoadError
10
- false
11
- end
12
-
13
- require_plugin 'autotest/clear'
14
-
15
- Autotest.add_hook :initialize do |at|
16
- # at.testlib = "minitest/unit"
17
- #
18
- # at.extra_files << "../some/external/dependency.rb"
19
- #
20
- # at.libs << ":../some/external"
21
- #
22
- # at.add_exception "vendor"
23
- #
24
- # at.add_mapping(/dependency.rb/) do |f, _|
25
- # at.files_matching(/test_.*rb$/)
26
- # end
27
- #
28
- # %w(TestA TestB).each do |klass|
29
- # at.extra_class_map[klass] = "test/test_misc.rb"
30
- # end
31
- end
32
-
33
- # Autotest.add_hook :run_command do |at|
34
- # system "rake build"
35
- # end
data/.gemtest DELETED
File without changes
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.md
2
- *.swp
3
- *~
4
- .rake_tasks~
5
- .source_index
6
- .vagrant
7
- Gemfile.lock
8
- Vagrantfile
9
- coverage
10
- doc
11
- html
12
- pkg
13
- publish
14
- test/cache.tst
15
- tmp/
16
- .rubocop.yml
17
- .byebug_history
data/.hoerc DELETED
@@ -1,20 +0,0 @@
1
- ---
2
- exclude: !ruby/regexp '/
3
- \.(tmp|swp)$
4
- |
5
- (CVS|tmp)\/
6
- |
7
- (?i:TAGS)
8
- |
9
- \.(svn|git|hg|DS_Store|idea|vagrant)\/
10
- |
11
- Gemfile(?:\.lock)?
12
- |
13
- \.(rubocop|coveralls|pullreview|travis).yml$
14
- |
15
- \.gemspec
16
- |
17
- \.byebug_history
18
- |
19
- Vagrantfile
20
- /x'
@@ -1,65 +0,0 @@
1
- # -*- ruby encoding: utf-8 -*-
2
-
3
- require 'benchmark'
4
- require 'mime/types'
5
-
6
- module Benchmarks
7
- class Load
8
- def self.report(load_path, repeats)
9
- new(load_path, repeats.to_i).report
10
- end
11
-
12
- def initialize(load_path, repeats = nil)
13
- @cache_file = File.expand_path('../cache.mtc', __FILE__)
14
- @repeats = repeats.to_i
15
- @repeats = 50 if @repeats <= 0
16
- @load_path = load_path
17
- end
18
-
19
- def reload_mime_types(repeats = 1, force: false, columnar: false, cache: false)
20
- loader = MIME::Types::Loader.new
21
-
22
- repeats.times {
23
- types = MIME::Types::Cache.load if cache
24
- unless types
25
- types = loader.load(columnar: columnar)
26
- MIME::Types::Cache.save(types) if cache
27
- end
28
- types.first.to_h if force
29
- }
30
- end
31
-
32
- def report
33
- remove_cache
34
-
35
- Benchmark.bm(30) do |mark|
36
- mark.report('Normal') { reload_mime_types(@repeats) }
37
- mark.report('Columnar') {
38
- reload_mime_types(@repeats, columnar: true)
39
- }
40
- mark.report('Columnar Full') {
41
- reload_mime_types(@repeats, columnar: true, force: true)
42
- }
43
-
44
- ENV['RUBY_MIME_TYPES_CACHE'] = @cache_file
45
- mark.report('Cache Initialize') { reload_mime_types(cache: true) }
46
- mark.report('Cached') { reload_mime_types(@repeats, cache: true) }
47
-
48
- remove_cache
49
- ENV['RUBY_MIME_TYPES_CACHE'] = @cache_file
50
- mark.report('Columnar Cache Initialize') {
51
- reload_mime_types(columnar: true, cache: true)
52
- }
53
- mark.report('Columnar Cached') {
54
- reload_mime_types(@repeats, columnar: true, cache: true)
55
- }
56
- end
57
- ensure
58
- remove_cache
59
- end
60
-
61
- def remove_cache
62
- File.unlink(@cache_file) if File.exist?(@cache_file)
63
- end
64
- end
65
- end
@@ -1,90 +0,0 @@
1
- # -*- ruby encoding: utf-8 -*-
2
-
3
- if RUBY_VERSION < '2.1'
4
- $stderr.puts "Cannot count allocations on #{RUBY_VERSION}."
5
- exit 1
6
- end
7
-
8
- begin
9
- require 'allocation_tracer'
10
- rescue LoadError
11
- $stderr.puts "Allocation tracking requires the gem 'allocation_tracer'."
12
- exit 1
13
- end
14
-
15
- module Benchmarks
16
- class LoadAllocations
17
- def self.report(columnar: false, full: false, top_x: nil, mime_types_only: false)
18
- new(
19
- columnar: columnar,
20
- top_x: top_x,
21
- mime_types_only: mime_types_only,
22
- full: full
23
- ).report
24
- end
25
-
26
- def initialize(columnar: false, full: false, top_x: nil, mime_types_only: false)
27
- @columnar = !!columnar
28
- @full = !!full
29
- @mime_types_only = !!mime_types_only
30
-
31
- @top_x = top_x
32
-
33
- return unless @top_x
34
- @top_x = top_x.to_i
35
- @top_x = 10 if @top_x <= 0
36
- end
37
-
38
- def report
39
- collect
40
- report_top_x if @top_x
41
- puts "TOTAL Allocations: #{@count}"
42
- end
43
-
44
- private
45
-
46
- def report_top_x
47
- table = @allocations.sort_by { |_, v| v.first }.reverse.first(@top_x)
48
- table.map! { |(location, allocs)|
49
- next if @mime_types_only and location.first !~ %r{mime-types/lib}
50
- [ location.join(':').gsub(%r{^#{Dir.pwd}/}, ''), *allocs ]
51
- }.compact!
52
-
53
- head = (ObjectSpace::AllocationTracer.header - [ :line ]).map {|h|
54
- h.to_s.split(/_/).map(&:capitalize).join(' ')
55
- }
56
- table.unshift head
57
-
58
- max_widths = [].tap do |mw|
59
- table.map { |row| row.lazy.map(&:to_s).map(&:length).to_a }.tap do |w|
60
- w.first.each_index do |i|
61
- mw << w.lazy.map { |r| r[i] }.max
62
- end
63
- end
64
- end
65
-
66
- pattern = [ '%%-%ds' ]
67
- pattern << ([ '%% %ds' ] * (max_widths.length - 1))
68
- pattern = pattern.join("\t") % max_widths
69
- table.each { |row| puts pattern % row }
70
- puts
71
- end
72
-
73
- def collect
74
- if @columnar
75
- @allocations = ObjectSpace::AllocationTracer.trace do
76
- require 'mime/types'
77
-
78
- MIME::Types.first.to_h if @full
79
- end
80
- else
81
- @allocations = ObjectSpace::AllocationTracer.trace do
82
- require 'mime/types/full'
83
- end
84
- end
85
-
86
- @count = ObjectSpace::AllocationTracer.allocated_count_table.values.
87
- inject(:+)
88
- end
89
- end
90
- end
@@ -1,43 +0,0 @@
1
- # -*- ruby encoding: utf-8 -*-
2
-
3
- module Benchmarks
4
- class ObjectCounts
5
- def self.report(columnar: false, full: false)
6
- new(columnar: columnar).report
7
- end
8
-
9
- def initialize(columnar: false, full: false)
10
- @columnar = columnar
11
- @full = full
12
- end
13
-
14
- def report
15
- collect
16
- @before.keys.grep(/T_/).map { |key|
17
- [ key, @after[key] - @before[key] ]
18
- }.sort_by { |_, delta| -delta }.each { |key, delta|
19
- puts '%10s +%6d' % [ key, delta ]
20
- }
21
- end
22
-
23
- private
24
-
25
- def collect
26
- @before = count_objects
27
-
28
- if @columnar
29
- require 'mime/types'
30
- MIME::Types.first.to_h if @full
31
- else
32
- require 'mime/types/full'
33
- end
34
-
35
- @after = count_objects
36
- end
37
-
38
- def count_objects
39
- GC.start
40
- ObjectSpace.count_objects
41
- end
42
- end
43
- end
@@ -1,5 +0,0 @@
1
- loader = MIME::Types::Loader.new
2
-
3
- 50.times do
4
- loader.load(columnar: true)
5
- end
@@ -1,5 +0,0 @@
1
- loader = MIME::Types::Loader.new
2
-
3
- 50.times do
4
- loader.load(columnar: true).first.to_h
5
- end
@@ -1,5 +0,0 @@
1
- loader = MIME::Types::Loader.new
2
-
3
- 50.times do
4
- loader.load(columnar: false)
5
- end