mime-types 2.99.3 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +5 -5
  2. data/{Code-of-Conduct.rdoc → Code-of-Conduct.md} +19 -20
  3. data/Contributing.md +139 -0
  4. data/History.md +208 -0
  5. data/{Licence.rdoc → Licence.md} +4 -18
  6. data/Manifest.txt +8 -25
  7. data/README.rdoc +63 -67
  8. data/Rakefile +144 -55
  9. data/lib/mime/type/columnar.rb +29 -62
  10. data/lib/mime/type.rb +192 -417
  11. data/lib/mime/types/_columnar.rb +137 -0
  12. data/lib/mime/types/cache.rb +51 -73
  13. data/lib/mime/types/columnar.rb +2 -147
  14. data/lib/mime/types/container.rb +94 -0
  15. data/lib/mime/types/deprecations.rb +5 -24
  16. data/lib/mime/types/full.rb +19 -0
  17. data/lib/mime/types/loader.rb +12 -141
  18. data/lib/mime/types/logger.rb +4 -0
  19. data/lib/mime/types/registry.rb +90 -0
  20. data/lib/mime/types.rb +43 -139
  21. data/lib/mime-types.rb +1 -1
  22. data/test/minitest_helper.rb +6 -12
  23. data/test/test_mime_type.rb +473 -455
  24. data/test/test_mime_types.rb +136 -86
  25. data/test/test_mime_types_cache.rb +83 -53
  26. data/test/test_mime_types_class.rb +119 -97
  27. data/test/test_mime_types_lazy.rb +27 -23
  28. data/test/test_mime_types_loader.rb +7 -32
  29. metadata +102 -62
  30. data/Contributing.rdoc +0 -170
  31. data/History-Types.rdoc +0 -454
  32. data/History.rdoc +0 -590
  33. data/data/mime-types.json +0 -1
  34. data/data/mime.content_type.column +0 -1980
  35. data/data/mime.docs.column +0 -1980
  36. data/data/mime.encoding.column +0 -1980
  37. data/data/mime.friendly.column +0 -1980
  38. data/data/mime.obsolete.column +0 -1980
  39. data/data/mime.registered.column +0 -1980
  40. data/data/mime.signature.column +0 -1980
  41. data/data/mime.use_instead.column +0 -1980
  42. data/data/mime.xrefs.column +0 -1980
  43. data/docs/COPYING.txt +0 -339
  44. data/docs/artistic.txt +0 -127
  45. data/lib/mime/types/loader_path.rb +0 -15
  46. data/support/apache_mime_types.rb +0 -108
  47. data/support/benchmarks/load.rb +0 -64
  48. data/support/benchmarks/load_allocations.rb +0 -83
  49. data/support/benchmarks/object_counts.rb +0 -41
  50. data/support/convert/columnar.rb +0 -88
  51. data/support/convert.rb +0 -158
  52. data/support/iana_registry.rb +0 -172
data/README.rdoc CHANGED
@@ -1,11 +1,11 @@
1
- = mime-types
1
+ = mime-types for Ruby
2
2
 
3
3
  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
 
@@ -14,19 +14,13 @@ MIME content type definitions. It can be used to determine defined filename
14
14
  extensions for MIME types, or to use filename extensions to look up the likely
15
15
  MIME type definitions.
16
16
 
17
- This is release 2.99.1, the first scheduled data update for mime-types 2.x. As
18
- of mime-types 2.99. deprecation warnings are noisy and data that has been
19
- deprecated is now no longer available. The data is both dropped from the data
20
- files and is stubbed out as empty or +nil+ values as appropriate.
21
-
22
- mime-types-2.6 was the last version of mime-types 2.x with newly available
23
- features, and mime-types 2.99 will only receive quarterly updates to the IANA
24
- registered MIME media types plus any security updates that may be required.
25
-
26
- If the loss of the deprecated data matters, be sure to set your dependency
27
- appropriately:
28
-
29
- gem 'mime-types', '~> 2.6, < 2.99'
17
+ Version 3.0 is a major release that requires Ruby 2.0 compatibility and removes
18
+ deprecated functions. The columnar registry format introduced in 2.6 has been
19
+ made the primary format; the registry data has been extracted from this library
20
+ and put into {mime-types-data}[https://github.com/mime-types/mime-types-data].
21
+ Additionally, mime-types is now licensed exclusively under the MIT licence and
22
+ there is a code of conduct in effect. There are a number of other smaller
23
+ changes described in the History file.
30
24
 
31
25
  === About MIME Media Types
32
26
 
@@ -43,14 +37,11 @@ user contributions. It conforms to RFCs 2045 and 2231.
43
37
 
44
38
  === mime-types 1.x End of Life
45
39
 
46
- mime-types 1.x has reached end of life and is no longer supported as of
47
- 2015-10-27 and will receive no updates at all.
40
+ mime-types 1.x is no longer supported as of 2015-10-27.
48
41
 
49
42
  === mime-types 2.x End of Life
50
43
 
51
- mime-types 2.x is supported as 2.99.x receiving quarterly updates of the IANA
52
- registry and security updates for two years. It will reach full end of life on
53
- 2017-11-21.
44
+ mime-types 2.x is no longer supported as of 2017-11-21.
54
45
 
55
46
  === mime-types 3.x
56
47
 
@@ -90,8 +81,8 @@ files). A MIME::Type stores the known information about one MIME type.
90
81
  puts text == 'text/x-plain' # => false
91
82
  puts 'text/x-plain' == text # => false
92
83
 
93
- puts MIME::Type.simplified('x-appl/x-zip') # => 'appl/zip'
94
- puts MIME::Type.i18n_key('x-appl/x-zip') # => 'appl.zip'
84
+ puts MIME::Type.simplified('x-appl/x-zip') # => 'x-appl/x-zip'
85
+ puts MIME::Type.i18n_key('x-appl/x-zip') # => 'x-appl.x-zip'
95
86
 
96
87
  puts text.like?('text/x-plain') # => true
97
88
  puts text.like?(MIME::Type.new('x-text/x-plain')) # => true
@@ -118,54 +109,61 @@ files). A MIME::Type stores the known information about one MIME type.
118
109
 
119
110
  xwingz = MIME::Types['application/x-Wingz'].first # => application/x-Wingz
120
111
  puts xwingz.content_type # => 'application/x-Wingz'
121
- puts xwingz.simplified # => 'application/wingz'
112
+ puts xwingz.simplified # => 'application/x-wingz'
122
113
 
123
114
  === Columnar Store
124
115
 
125
- mime-types 2.6 introduced an experimental columnar storage format that reduces
126
- the default memory footprint. It does this by selectively loading data. When a
127
- registry is first loaded from a columnar store, only the canonical MIME type
128
- and registered extensions will be loaded and the MIME type will be connected to
129
- its registry. When extended data is required (including +registered+,
130
- +obsolete+, and +use_instead+), that data is loaded from its own column file
131
- for all types in the registry. This load is done with a Mutex to ensure that
132
- the types are updated safely in a multithreaded environment.
116
+ mime-types uses as its primary registry storage format a columnar storage
117
+ format reducing the default memory footprint. This is done by selectively
118
+ loading the data on a per-attribute basis. When the registry is first loaded
119
+ from the columnar store, only the canonical MIME content type and known
120
+ extensions and the MIME type will be connected to its loading registry. When
121
+ other data about the type is required (including +preferred_extension+,
122
+ <tt>obsolete?</tt>, and <tt>registered?</tt>) that data is loaded from its own
123
+ column file for all types in the registry.
133
124
 
134
- Columnar storage is slated to become the default storage format for mime-types
135
- 3.0, but until that is released, the default is still to use the JSON storage
136
- format. As such, columnar storage can only currently be loaded at an
137
- application level with the following specification in the application Gemfile:
125
+ The load of any column data is performed with a Mutex to ensure that types are
126
+ updated safely in a multithreaded environment. Benchmarks show that while
127
+ columnar data loading is slower than the JSON store, it cuts the memory use by
128
+ a third over the JSON store.
138
129
 
139
- gem 'mime-types', require: 'mime/types/columnar'
130
+ If you prefer to load all the data at once, this can be specified in your
131
+ application Gemfile as:
140
132
 
141
- Projects that do not use Bundler, and libraries that wish to suggest this
142
- behaviour to applications are encouraged to require this directly, but only if
143
- you specify a dependency on mime-types 2.6.
133
+ gem 'mime-types', require: 'mime/types/full'
144
134
 
145
- require 'mime/types/columnar'
135
+ Projects that do not use Bundler should +require+ the same:
146
136
 
147
- Although this require will not be necessary after mime-types 3, it will work
148
- through at least {version
137
+ require 'mime/types/full'
138
+
139
+ Libraries that use mime-types are discouraged from choosing the JSON store.
140
+
141
+ For applications and clients that used mime-types 2.6 when the columnar store
142
+ was introduced, the require used previously will still work through at least
143
+ {version
149
144
  4}[https://github.com/mime-types/ruby-mime-types/pull/96#issuecomment-100725400]
150
- and possibly beyond.
145
+ and possibly beyond; it is effectively an empty operation. You are recommended
146
+ to change your Gemfile as soon as is practical.
147
+
148
+ require 'mime/types/columnar'
151
149
 
152
- Note that the new Columnar class (MIME::Type::Columnar) and module
153
- (MIME::Types::Columnar) are considered private variant implementations of
154
- MIME::Type and MIME::Types and the specific implementation should not be relied
155
- upon by consumers of the mime-types library. Instead, depend on the public
156
- implementations only.
150
+ Note that MIME::Type::Columnar and MIME::Types::Columnar are considered private
151
+ variant implementations of MIME::Type and MIME::Types and the specific
152
+ implementation should not be relied upon by consumers of the mime-types
153
+ library. Instead, depend on the public implementations (MIME::Type and
154
+ MIME::Types) only.
157
155
 
158
156
  === Cached Storage
159
157
 
160
- Since version 2.0, mime-types has supported a cache of MIME types based on
161
- <tt>Marshal.dump</tt>. The cache is invalidated for each released version of
162
- mime-types so that version 2.5 is not reused for version 2.6. If the
158
+ mime-types supports a cache of MIME types using <tt>Marshal.dump</tt>. The
159
+ cache is invalidated for each version of the mime-types-data gem so that data
160
+ version 3.2015.1201 will not be reused with data version 3.2016.0101. If the
163
161
  environment variable +RUBY_MIME_TYPES_CACHE+ is set to a cache file, mime-types
164
162
  will attempt to load the MIME type registry from the cache file. If it cannot,
165
163
  it will load the types normally and then saves the registry to the cache file.
166
164
 
167
- The current mime-types cache is not compatible with the columnar storage
168
- format. This will be resolved for mime-types 3.
165
+ The caching works with both full stores and columnar stores. Only the data that
166
+ has been loaded prior to saving the cache will be stored.
169
167
 
170
168
  == mime-types Modified Semantic Versioning
171
169
 
@@ -183,22 +181,20 @@ MAJOR.MINOR:
183
181
  incremented, MINOR will be set to zero, and PATCH will be reset to the
184
182
  implied zero.
185
183
 
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.
184
+ 2. If an API (code) feature is added that does not break compatibility, the
185
+ MINOR version will be incremented and PATCH will be reset to the implied zero.
189
186
 
190
187
  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.
188
+ release, the implied PATCH value will be incremented resulting in
189
+ MAJOR.MINOR.PATCH.
193
190
 
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.
191
+ In practical terms, there will be fewer releases of mime-types focussing on
192
+ features because of the existence of the [mime-types-data][] gem, and if
193
+ features are marked deprecated in the course of mime-types 3.x, they will not
194
+ be removed until mime-types 4.x or possibly later.
199
195
 
200
- :include: Code-of-Conduct.rdoc
196
+ {Code of Conduct}[Code-of-Conduct_md.html]
201
197
 
202
- :include: Contributing.rdoc
198
+ {Contributing}[Contributing_md.html]
203
199
 
204
- :include: Licence.rdoc
200
+ {Licence}[Licence_md.html]
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # -*- ruby encoding: utf-8 -*-
4
+
3
5
  require 'rubygems'
4
6
  require 'hoe'
5
7
  require 'rake/clean'
@@ -15,13 +17,14 @@ spec = Hoe.spec 'mime-types' do
15
17
  developer('Austin Ziegler', 'halostatue@gmail.com')
16
18
  self.need_tar = true
17
19
 
18
- require_ruby_version '>= 1.9.2'
20
+ require_ruby_version '>= 2.0'
19
21
 
20
- self.history_file = 'History.rdoc'
22
+ self.history_file = 'History.md'
21
23
  self.readme_file = 'README.rdoc'
22
- self.extra_rdoc_files = FileList['*.rdoc'].to_a
23
24
 
24
- self.licenses = ['MIT', 'Artistic-2.0', 'GPL-2.0']
25
+ license 'MIT'
26
+
27
+ extra_deps << ['mime-types-data', '~> 3.2015']
25
28
 
26
29
  extra_dev_deps << ['hoe-doofus', '~> 1.0']
27
30
  extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
@@ -31,28 +34,29 @@ spec = Hoe.spec 'mime-types' do
31
34
  extra_dev_deps << ['minitest', '~> 5.4']
32
35
  extra_dev_deps << ['minitest-autotest', '~> 1.0']
33
36
  extra_dev_deps << ['minitest-focus', '~> 1.0']
34
- extra_dev_deps << ['rake', '~> 10.0']
37
+ extra_dev_deps << ['minitest-bonus-assertions', '~> 3.0']
38
+ extra_dev_deps << ['minitest-hooks', '~> 1.4']
39
+ extra_dev_deps << ['rake', '>= 10.0', '< 13.0']
35
40
  extra_dev_deps << ['fivemat', '~> 1.3' ]
36
41
  extra_dev_deps << ['minitest-rg', '~> 5.2']
37
- end
38
-
39
- task :support do
40
- %w(lib support).each { |path|
41
- $LOAD_PATH.unshift(File.join(Rake.application.original_dir, path))
42
- }
43
- end
44
42
 
45
- task 'support:nokogiri' => :support do
46
- begin
47
- gem 'nokogiri'
48
- rescue Gem::LoadError
49
- raise 'Nokogiri is not installed. Please install it.'
43
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.0')
44
+ extra_dev_deps << ['simplecov', '~> 0.7']
45
+ # if ENV['CI'] or ENV['TRAVIS']
46
+ # extra_dev_deps << ['coveralls', '~> 0.8']
47
+ # end
50
48
  end
51
49
  end
52
50
 
53
51
  namespace :benchmark do
52
+ task :support do
53
+ %w(lib support).each { |path|
54
+ $LOAD_PATH.unshift(File.join(Rake.application.original_dir, path))
55
+ }
56
+ end
57
+
54
58
  desc 'Benchmark Load Times'
55
- task :load, [ :repeats ] => :support do |_, args|
59
+ task :load, [ :repeats ] => 'benchmark:support' do |_, args|
56
60
  require 'benchmarks/load'
57
61
  Benchmarks::Load.report(
58
62
  File.join(Rake.application.original_dir, 'lib'),
@@ -61,7 +65,7 @@ namespace :benchmark do
61
65
  end
62
66
 
63
67
  desc 'Allocation counts'
64
- task :allocations, [ :top_x, :mime_types_only ] => :support do |_, args|
68
+ task :allocations, [ :top_x, :mime_types_only ] => 'benchmark:support' do |_, args|
65
69
  require 'benchmarks/load_allocations'
66
70
  Benchmarks::LoadAllocations.report(
67
71
  top_x: args.top_x,
@@ -70,7 +74,7 @@ namespace :benchmark do
70
74
  end
71
75
 
72
76
  desc 'Columnar allocation counts'
73
- task 'allocations:columnar', [ :top_x, :mime_types_only ] => :support do |_, args|
77
+ task 'allocations:columnar', [ :top_x, :mime_types_only ] => 'benchmark:support' do |_, args|
74
78
  require 'benchmarks/load_allocations'
75
79
  Benchmarks::LoadAllocations.report(
76
80
  columnar: true,
@@ -79,30 +83,102 @@ namespace :benchmark do
79
83
  )
80
84
  end
81
85
 
86
+ desc 'Columnar allocation counts (full load)'
87
+ task 'allocations:columnar:full', [ :top_x, :mime_types_only ] => 'benchmark:support' do |_, args|
88
+ require 'benchmarks/load_allocations'
89
+ Benchmarks::LoadAllocations.report(
90
+ columnar: true,
91
+ top_x: args.top_x,
92
+ mime_types_only: args.mime_types_only,
93
+ full: true
94
+ )
95
+ end
96
+
82
97
  desc 'Object counts'
83
- task objects: :support do
98
+ task objects: 'benchmark:support' do
84
99
  require 'benchmarks/object_counts'
85
100
  Benchmarks::ObjectCounts.report
86
101
  end
87
102
 
88
103
  desc 'Columnar object counts'
89
- task 'objects:columnar' => :support do
104
+ task 'objects:columnar' => 'benchmark:support' do
90
105
  require 'benchmarks/object_counts'
91
106
  Benchmarks::ObjectCounts.report(columnar: true)
92
107
  end
108
+
109
+ desc 'Columnar object counts (full load)'
110
+ task 'objects:columnar:full' => 'benchmark:support' do
111
+ require 'benchmarks/object_counts'
112
+ Benchmarks::ObjectCounts.report(columnar: true, full: true)
113
+ end
93
114
  end
94
115
 
95
- namespace :mime do
96
- desc 'Download the current MIME type registrations from IANA.'
97
- task :iana, [ :destination ] => 'support:nokogiri' do |_, args|
98
- require 'iana_registry'
99
- IANARegistry.download(to: args.destination)
116
+ namespace :profile do
117
+ directory 'tmp/profile'
118
+
119
+ CLEAN.add 'tmp'
120
+
121
+ def ruby_prof(script)
122
+ require 'pathname'
123
+ output = Pathname('tmp/profile').join(script)
124
+ output.mkpath
125
+ script = Pathname('support/profile').join("#{script}.rb")
126
+
127
+ args = [
128
+ '-W0',
129
+ '-Ilib',
130
+ '-S', 'ruby-prof',
131
+ '-R', 'mime/types',
132
+ '-s', 'self',
133
+ '-p', 'multi',
134
+ '-f', "#{output}",
135
+ script.to_s
136
+ ]
137
+ ruby args.join(' ')
138
+ end
139
+
140
+ task full: 'tmp/profile' do
141
+ ruby_prof 'full'
142
+ end
143
+
144
+ task columnar: :support do
145
+ ruby_prof 'columnar'
100
146
  end
101
147
 
102
- desc 'Download the current MIME type configuration from Apache.'
103
- task :apache, [ :destination ] => 'support:nokogiri' do |_, args|
104
- require 'apache_mime_types'
105
- ApacheMIMETypes.download(to: args.destination)
148
+ task 'columnar:full' => :support do
149
+ ruby_prof 'columnar_full'
150
+ end
151
+ end
152
+
153
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.0')
154
+ namespace :test do
155
+ # Coveralls needs to be disabled for now because it transitively depends on
156
+ # an earlier version of mime-types.
157
+ # if ENV['CI'] or ENV['TRAVIS']
158
+ # task :coveralls do
159
+ # spec.test_prelude = [
160
+ # 'require "psych"',
161
+ # 'require "simplecov"',
162
+ # 'require "coveralls"',
163
+ # 'SimpleCov.formatter = Coveralls::SimpleCov::Formatter',
164
+ # 'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
165
+ # 'gem "minitest"'
166
+ # ].join('; ')
167
+ # Rake::Task['test'].execute
168
+ # end
169
+
170
+ # Rake::Task['travis'].prerequisites.replace(%w(test:coveralls))
171
+ # end
172
+
173
+ desc 'Run test coverage'
174
+ task :coverage do
175
+ spec.test_prelude = [
176
+ 'require "simplecov"',
177
+ 'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
178
+ 'gem "minitest"'
179
+ ].join('; ')
180
+ Rake::Task['test'].execute
181
+ end
106
182
  end
107
183
  end
108
184
 
@@ -114,9 +190,9 @@ namespace :convert do
114
190
  @doc_converter ||= RDoc::Markup::ToMarkdown.new
115
191
  end
116
192
 
117
- %w(README History History-Types).each do |name|
118
- rdoc = "#{name}.rdoc"
119
- mark = "#{name}.md"
193
+ FileList['*.rdoc'].each do |name|
194
+ rdoc = name
195
+ mark = "#{File.basename(name, '.rdoc')}.md"
120
196
 
121
197
  file mark => [ rdoc, :setup ] do |t|
122
198
  puts "#{rdoc} => #{mark}"
@@ -133,35 +209,48 @@ namespace :convert do
133
209
 
134
210
  desc 'Convert documentation from RDoc to Markdown'
135
211
  task docs: 'convert:docs:run'
212
+ end
136
213
 
137
- namespace :yaml do
138
- desc 'Convert from YAML to JSON'
139
- task :json, [ :source, :destination, :multiple_files ] => :support do |_, args|
140
- require 'convert'
141
- Convert.from_yaml_to_json(args)
142
- end
214
+ task 'deps:top', [ :number ] do |_, args|
215
+ require 'net/http'
216
+ require 'json'
143
217
 
144
- desc 'Convert from YAML to Columnar'
145
- task :columnar, [ :source, :destination ] => :support do |_, args|
146
- require 'convert/columnar'
147
- Convert::Columnar.from_yaml_to_columnar(args)
218
+ def rubygems_get(gem_name: '', endpoint: '')
219
+ path = File.join('/api/v1/gems/', gem_name, endpoint).chomp('/') + '.json'
220
+ Net::HTTP.start('rubygems.org', use_ssl: true) do |http|
221
+ JSON.parse(http.get(path).body)
148
222
  end
149
223
  end
150
224
 
151
- namespace :json do
152
- desc 'Convert from JSON to YAML'
153
- task :yaml, [ :source, :destination, :multiple_files ] => :support do |_, args|
154
- require 'convert'
155
- Convert.from_json_to_yaml(args)
225
+ results = rubygems_get(
226
+ gem_name: 'mime-types',
227
+ endpoint: 'reverse_dependencies'
228
+ )
229
+
230
+ weighted_results = {}
231
+ results.each do |name|
232
+ begin
233
+ weighted_results[name] = rubygems_get(gem_name: name)['downloads']
234
+ rescue => e
235
+ puts "#{name} #{e.message}"
156
236
  end
157
237
  end
158
- end
159
238
 
160
- desc 'Default conversion from YAML to JSON and Columnar'
161
- task convert: [ 'convert:yaml:json', 'convert:yaml:columnar' ]
239
+ weighted_results.sort { |(_k1, v1), (_k2, v2)|
240
+ v2 <=> v1
241
+ }.first(args.number || 50).each_with_index do |(k, v), i|
242
+ puts "#{i}) #{k}: #{v}"
243
+ end
244
+ end
162
245
 
163
- Rake::Task['gem'].prerequisites.unshift('convert')
164
- Rake::Task['gem'].prerequisites.unshift('git:manifest')
165
- Rake::Task['gem'].prerequisites.unshift('gemspec')
246
+ task :console do
247
+ arguments = %w(pry)
248
+ arguments.push(*spec.spec.require_paths.map { |dir| "-I#{dir}" })
249
+ arguments.push("-r#{spec.spec.name.gsub('-', File::SEPARATOR)}")
250
+ unless system(*arguments)
251
+ error "Command failed: #{show_command}"
252
+ abort
253
+ end
254
+ end
166
255
 
167
256
  # vim: syntax=ruby
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mime/type'
2
4
 
3
5
  # A version of MIME::Type that works hand-in-hand with a MIME::Types::Columnar
@@ -11,80 +13,45 @@ require 'mime/type'
11
13
  # MIME::Type::Columnar is *not* intended to be created except by
12
14
  # MIME::Types::Columnar containers.
13
15
  class MIME::Type::Columnar < MIME::Type
14
- attr_writer :friendly # :nodoc:
15
-
16
16
  def initialize(container, content_type, extensions) # :nodoc:
17
17
  @container = container
18
18
  self.content_type = content_type
19
19
  self.extensions = extensions
20
20
  end
21
21
 
22
- def friendly(*) # :nodoc:
23
- @container.send(:load_friendly) unless defined?(@friendly)
24
- super if @friendly
25
- end
26
-
27
- def encoding # :nodoc:
28
- @container.send(:load_encoding) unless defined?(@encoding)
29
- @encoding
30
- end
31
-
32
- def docs # :nodoc:
33
- @container.send(:load_docs) unless defined?(@docs)
34
- @docs
35
- end
36
-
37
- def obsolete? # :nodoc:
38
- @container.send(:load_obsolete) unless defined?(@obsolete)
39
- super
40
- end
41
-
42
- def registered? # :nodoc:
43
- @container.send(:load_registered) unless defined?(@registered)
44
- super
45
- end
46
-
47
- def signature? # :nodoc:
48
- @container.send(:load_signature) unless defined?(@signature)
49
- super
50
- end
22
+ def self.column(*methods, file: nil) # :nodoc:
23
+ file = methods.first unless file
51
24
 
52
- def xrefs # :nodoc:
53
- @container.send(:load_xrefs) unless defined?(@xrefs)
54
- @xrefs
25
+ file_method = :"load_#{file}"
26
+ methods.each do |m|
27
+ define_method m do |*args|
28
+ @container.send(file_method)
29
+ super(*args)
30
+ end
31
+ end
55
32
  end
56
33
 
57
- def use_instead # :nodoc:
58
- @container.send(:load_use_instead) unless defined?(@use_instead)
59
- @use_instead
60
- end
61
-
62
- def binary? # :nodoc:
63
- @container.send(:load_encoding) unless defined?(@encoding)
64
- super
65
- end
34
+ column :friendly
35
+ column :encoding, :encoding=
36
+ column :docs, :docs=
37
+ column :preferred_extension, :preferred_extension=
38
+ column :obsolete, :obsolete=, :obsolete?, :registered, :registered=,
39
+ :registered?, :signature, :signature=, :signature?, file: 'flags'
40
+ column :xrefs, :xrefs=, :xref_urls
41
+ column :use_instead, :use_instead=
66
42
 
67
- def to_a # :nodoc:
68
- @container.send(:load_encoding) unless defined?(@encoding)
69
- @container.send(:load_docs) unless defined?(@docs)
70
- super
71
- end
72
-
73
- def to_hash # :nodoc:
74
- @container.send(:load_encoding) unless defined?(@encoding)
75
- @container.send(:load_docs) unless defined?(@docs)
43
+ def encode_with(coder) # :nodoc:
44
+ @container.send(:load_friendly)
45
+ @container.send(:load_encoding)
46
+ @container.send(:load_docs)
47
+ @container.send(:load_flags)
48
+ @container.send(:load_use_instead)
49
+ @container.send(:load_xrefs)
50
+ @container.send(:load_preferred_extension)
76
51
  super
77
52
  end
78
53
 
79
- def encode_with(coder) # :nodoc:
80
- @container.send(:load_friendly) unless defined?(@friendly)
81
- @container.send(:load_encoding) unless defined?(@encoding)
82
- @container.send(:load_docs) unless defined?(@docs)
83
- @container.send(:load_obsolete) unless defined?(@obsolete)
84
- @container.send(:load_use_instead) unless defined?(@use_instead)
85
- @container.send(:load_xrefs) unless defined?(@xrefs)
86
- @container.send(:load_registered) unless defined?(@registered)
87
- @container.send(:load_signature) unless defined?(@signature)
88
- super
54
+ class << self
55
+ undef column
89
56
  end
90
57
  end