mime-types 1.17.2 → 3.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.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +35 -0
  3. data/.gitignore +17 -0
  4. data/.hoerc +20 -12
  5. data/Code-of-Conduct.rdoc +41 -0
  6. data/Contributing.rdoc +169 -0
  7. data/History.rdoc +531 -30
  8. data/Licence.rdoc +25 -0
  9. data/Manifest.txt +32 -34
  10. data/README.rdoc +198 -13
  11. data/Rakefile +181 -159
  12. data/lib/mime/type/columnar.rb +55 -0
  13. data/lib/mime/type.rb +566 -0
  14. data/lib/mime/types/cache.rb +56 -0
  15. data/lib/mime/types/columnar.rb +142 -0
  16. data/lib/mime/types/container.rb +30 -0
  17. data/lib/mime/types/deprecations.rb +32 -0
  18. data/lib/mime/types/full.rb +17 -0
  19. data/lib/mime/types/loader.rb +148 -0
  20. data/lib/mime/types/logger.rb +37 -0
  21. data/lib/mime/types/registry.rb +81 -0
  22. data/lib/mime/types.rb +199 -819
  23. data/lib/mime-types.rb +1 -0
  24. data/support/benchmarks/load.rb +65 -0
  25. data/support/benchmarks/load_allocations.rb +90 -0
  26. data/support/benchmarks/object_counts.rb +43 -0
  27. data/support/profile/columnar.rb +5 -0
  28. data/support/profile/columnar_full.rb +5 -0
  29. data/support/profile/full.rb +5 -0
  30. data/test/bad-fixtures/malformed +9 -0
  31. data/test/fixture/json.json +1 -0
  32. data/test/fixture/old-data +9 -0
  33. data/test/fixture/yaml.yaml +55 -0
  34. data/test/minitest_helper.rb +12 -0
  35. data/test/test_mime_type.rb +527 -242
  36. data/test/test_mime_types.rb +130 -68
  37. data/test/test_mime_types_cache.rb +100 -0
  38. data/test/test_mime_types_class.rb +155 -0
  39. data/test/test_mime_types_lazy.rb +43 -0
  40. data/test/test_mime_types_loader.rb +32 -0
  41. metadata +286 -229
  42. data/License.rdoc +0 -10
  43. data/lib/mime/types/application +0 -940
  44. data/lib/mime/types/application.mac +0 -2
  45. data/lib/mime/types/application.nonstandard +0 -114
  46. data/lib/mime/types/application.obsolete +0 -40
  47. data/lib/mime/types/audio +0 -131
  48. data/lib/mime/types/audio.nonstandard +0 -10
  49. data/lib/mime/types/audio.obsolete +0 -1
  50. data/lib/mime/types/image +0 -43
  51. data/lib/mime/types/image.nonstandard +0 -17
  52. data/lib/mime/types/image.obsolete +0 -5
  53. data/lib/mime/types/message +0 -19
  54. data/lib/mime/types/message.obsolete +0 -1
  55. data/lib/mime/types/model +0 -15
  56. data/lib/mime/types/multipart +0 -14
  57. data/lib/mime/types/multipart.nonstandard +0 -1
  58. data/lib/mime/types/multipart.obsolete +0 -7
  59. data/lib/mime/types/other.nonstandard +0 -8
  60. data/lib/mime/types/text +0 -54
  61. data/lib/mime/types/text.nonstandard +0 -5
  62. data/lib/mime/types/text.obsolete +0 -7
  63. data/lib/mime/types/text.vms +0 -1
  64. data/lib/mime/types/video +0 -68
  65. data/lib/mime/types/video.nonstandard +0 -11
  66. data/lib/mime/types/video.obsolete +0 -3
  67. data/mime-types.gemspec +0 -57
  68. data/type-lists/application.txt +0 -951
  69. data/type-lists/audio.txt +0 -132
  70. data/type-lists/image.txt +0 -43
  71. data/type-lists/message.txt +0 -20
  72. data/type-lists/model.txt +0 -15
  73. data/type-lists/multipart.txt +0 -14
  74. data/type-lists/text.txt +0 -57
  75. data/type-lists/video.txt +0 -67
data/Manifest.txt CHANGED
@@ -1,42 +1,40 @@
1
+ .autotest
2
+ .gemtest
3
+ .gitignore
1
4
  .hoerc
5
+ Code-of-Conduct.rdoc
6
+ Contributing.rdoc
2
7
  History.rdoc
3
- License.rdoc
8
+ Licence.rdoc
4
9
  Manifest.txt
5
10
  README.rdoc
6
11
  Rakefile
12
+ lib/mime-types.rb
13
+ lib/mime/type.rb
14
+ lib/mime/type/columnar.rb
7
15
  lib/mime/types.rb
8
- lib/mime/types/application
9
- lib/mime/types/application.mac
10
- lib/mime/types/application.nonstandard
11
- lib/mime/types/application.obsolete
12
- lib/mime/types/audio
13
- lib/mime/types/audio.nonstandard
14
- lib/mime/types/audio.obsolete
15
- lib/mime/types/image
16
- lib/mime/types/image.nonstandard
17
- lib/mime/types/image.obsolete
18
- lib/mime/types/message
19
- lib/mime/types/message.obsolete
20
- lib/mime/types/model
21
- lib/mime/types/multipart
22
- lib/mime/types/multipart.nonstandard
23
- lib/mime/types/multipart.obsolete
24
- lib/mime/types/other.nonstandard
25
- lib/mime/types/text
26
- lib/mime/types/text.nonstandard
27
- lib/mime/types/text.obsolete
28
- lib/mime/types/text.vms
29
- lib/mime/types/video
30
- lib/mime/types/video.nonstandard
31
- lib/mime/types/video.obsolete
32
- mime-types.gemspec
16
+ lib/mime/types/cache.rb
17
+ lib/mime/types/columnar.rb
18
+ lib/mime/types/container.rb
19
+ lib/mime/types/deprecations.rb
20
+ lib/mime/types/full.rb
21
+ lib/mime/types/loader.rb
22
+ lib/mime/types/logger.rb
23
+ 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
+ test/bad-fixtures/malformed
31
+ test/fixture/json.json
32
+ test/fixture/old-data
33
+ test/fixture/yaml.yaml
34
+ test/minitest_helper.rb
33
35
  test/test_mime_type.rb
34
36
  test/test_mime_types.rb
35
- type-lists/application.txt
36
- type-lists/audio.txt
37
- type-lists/image.txt
38
- type-lists/message.txt
39
- type-lists/model.txt
40
- type-lists/multipart.txt
41
- type-lists/text.txt
42
- type-lists/video.txt
37
+ test/test_mime_types_cache.rb
38
+ test/test_mime_types_class.rb
39
+ test/test_mime_types_lazy.rb
40
+ test/test_mime_types_loader.rb
data/README.rdoc CHANGED
@@ -1,19 +1,204 @@
1
- = MIME::Types for Ruby
1
+ = mime-types for Ruby
2
+
3
+ home :: https://github.com/mime-types/ruby-mime-types/
4
+ code :: https://github.com/mime-types/ruby-mime-types/
5
+ bugs :: https://github.com/mime-types/ruby-mime-types/issues
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]
2
9
 
3
10
  == Description
4
11
 
5
- This library allows for the identification of a file's likely MIME content
6
- type. This is release 1.17.2. The identification of MIME content type is based
7
- on a file's filename extensions.
12
+ The mime-types library provides a library and registry for information about
13
+ MIME content type definitions. It can be used to determine defined filename
14
+ extensions for MIME types, or to use filename extensions to look up the likely
15
+ MIME type definitions.
16
+
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.
24
+
25
+ === About MIME Media Types
26
+
27
+ MIME content types are used in MIME-compliant communications, as in e-mail or
28
+ HTTP traffic, to indicate the type of content which is transmitted. The
29
+ mime-types library provides the ability for detailed information about MIME
30
+ entities (provided as an enumerable collection of MIME::Type objects) to be
31
+ determined and used. There are many types defined by RFCs and vendors, so the
32
+ list is long but by definition incomplete; don't hesitate to add additional
33
+ type definitions. MIME type definitions found in mime-types are from RFCs, W3C
34
+ recommendations, the {IANA Media Types
35
+ registry}[https://www.iana.org/assignments/media-types/media-types.xhtml], and
36
+ user contributions. It conforms to RFCs 2045 and 2231.
37
+
38
+ === mime-types 1.x End of Life
39
+
40
+ mime-types 1.x is no longer supported as of 2015-10-27.
41
+
42
+ === mime-types 2.x End of Life
43
+
44
+ mime-types 2.x is supported as 2.99.x receiving quarterly updates of the IANA
45
+ registry and security updates for two years. It will reach full end of life on
46
+ 2017-11-21.
47
+
48
+ === mime-types 3.x
49
+
50
+ Users are encouraged to upgrade to mime-types 3.x as soon as is practical.
51
+ mime-types 3.x requires Ruby 2.0 compatibility and a simpler licensing scheme.
52
+
53
+ == Synopsis
54
+
55
+ MIME types are used in MIME entities, as in email or HTTP traffic. It is useful
56
+ at times to have information available about MIME types (or, inversely, about
57
+ files). A MIME::Type stores the known information about one MIME type.
58
+
59
+ require 'mime/types'
60
+
61
+ plaintext = MIME::Types['text/plain'] # => [ text/plain ]
62
+ text = plaintext.first
63
+ puts text.media_type # => 'text'
64
+ puts text.sub_type # => 'plain'
65
+
66
+ puts text.extensions.join(' ') # => 'txt asc c cc h hh cpp hpp dat hlp'
67
+ puts text.preferred_extension # => 'txt'
68
+ puts text.friendly # => 'Text Document'
69
+ puts text.i18n_key # => 'text.plain'
70
+
71
+ puts text.encoding # => quoted-printable
72
+ puts text.default_encoding # => quoted-printable
73
+ puts text.binary? # => false
74
+ puts text.ascii? # => true
75
+ puts text.obsolete? # => false
76
+ puts text.registered? # => true
77
+ puts text.complete? # => true
78
+
79
+ puts text # => 'text/plain'
80
+
81
+ puts text == 'text/plain' # => true
82
+ puts 'text/plain' == text # => true
83
+ puts text == 'text/x-plain' # => false
84
+ puts 'text/x-plain' == text # => false
85
+
86
+ puts MIME::Type.simplified('x-appl/x-zip') # => 'appl/zip'
87
+ puts MIME::Type.i18n_key('x-appl/x-zip') # => 'appl.zip'
88
+
89
+ puts text.like?('text/x-plain') # => true
90
+ puts text.like?(MIME::Type.new('x-text/x-plain')) # => true
91
+
92
+ puts text.xrefs.inspect # => { "rfc" => [ "rfc2046", "rfc3676", "rfc5147" ] }
93
+ puts text.xref_urls # => [ "http://www.iana.org/go/rfc2046",
94
+ # "http://www.iana.org/go/rfc3676",
95
+ # "http://www.iana.org/go/rfc5147" ]
96
+
97
+ xtext = MIME::Type.new('x-text/x-plain')
98
+ puts xtext.media_type # => 'text'
99
+ puts xtext.raw_media_type # => 'x-text'
100
+ puts xtext.sub_type # => 'plain'
101
+ puts xtext.raw_sub_type # => 'x-plain'
102
+ puts xtext.complete? # => false
103
+
104
+ puts MIME::Types.any? { |type| type.content_type == 'text/plain' } # => true
105
+ puts MIME::Types.all?(&:registered?) # => false
106
+
107
+ # Various string representations of MIME types
108
+ qcelp = MIME::Types['audio/QCELP'].first # => audio/QCELP
109
+ puts qcelp.content_type # => 'audio/QCELP'
110
+ puts qcelp.simplified # => 'audio/qcelp'
111
+
112
+ xwingz = MIME::Types['application/x-Wingz'].first # => application/x-Wingz
113
+ puts xwingz.content_type # => 'application/x-Wingz'
114
+ puts xwingz.simplified # => 'application/wingz'
115
+
116
+ === Columnar Store
117
+
118
+ mime-types uses as its primary registry storage format a columnar storage
119
+ format reducing the default memory footprint. This is done by selectively
120
+ loading the data on a per-attribute basis. When the registry is first loaded
121
+ from the columnar store, only the canonical MIME content type and known
122
+ extensions and the MIME type will be connected to its loading registry. When
123
+ other data about the type is required (including +preferred_extension+,
124
+ <tt>obsolete?</tt>, and <tt>registered?</tt>) that data is loaded from its own
125
+ column file for all types in the registry.
126
+
127
+ The load of any column data is performed with a Mutex to ensure that types are
128
+ updated safely in a multithreaded environment. Benchmarks show that while
129
+ columnar data loading is slower than the JSON store, it cuts the memory use by
130
+ a third over the JSON store.
131
+
132
+ If you prefer to load all the data at once, this can be specified in your
133
+ application Gemfile as:
134
+
135
+ gem 'mime-types', require: 'mime/types/full'
136
+
137
+ Projects that do not use Bundler should +require+ the same:
138
+
139
+ require 'mime/types/full'
140
+
141
+ Libraries that use mime-types are discouraged from choosing the JSON store.
142
+
143
+ For applications and clients that used mime-types 2.6 when the columnar store
144
+ was introduced, the require used previously will still work through at least
145
+ {version
146
+ 4}[https://github.com/mime-types/ruby-mime-types/pull/96#issuecomment-100725400]
147
+ and possibly beyond; it is effectively an empty operation. You are recommended
148
+ to change your Gemfile as soon as is practical.
149
+
150
+ require 'mime/types/columnar'
151
+
152
+ Note that MIME::Type::Columnar and MIME::Types::Columnar are considered private
153
+ variant implementations of MIME::Type and MIME::Types and the specific
154
+ implementation should not be relied upon by consumers of the mime-types
155
+ library. Instead, depend on the public implementations (MIME::Type and
156
+ MIME::Types) only.
157
+
158
+ === Cached Storage
159
+
160
+ mime-types supports a cache of MIME types using <tt>Marshal.dump</tt>. The
161
+ cache is invalidated for each version of the mime-types-data gem so that data
162
+ version 3.2015.1201 will not be reused with data version 3.2016.0101. If the
163
+ environment variable +RUBY_MIME_TYPES_CACHE+ is set to a cache file, mime-types
164
+ will attempt to load the MIME type registry from the cache file. If it cannot,
165
+ it will load the types normally and then saves the registry to the cache file.
166
+
167
+ The caching works with both full stores and columnar stores. Only the data that
168
+ has been loaded prior to saving the cache will be stored.
169
+
170
+ == mime-types Modified Semantic Versioning
171
+
172
+ The mime-types library has one version number, but this single version number
173
+ tracks both API changes and registry data changes; this is not wholly
174
+ compatible with all aspects of {Semantic Versioning}[http://semver.org/];
175
+ removing a MIME type from the registry *could* be considered a breaking change
176
+ under some interpretations of semantic versioning (as lookups for that
177
+ particular type would no longer work by default).
178
+
179
+ mime-types uses a modified semantic versioning scheme. Given the version
180
+ MAJOR.MINOR:
181
+
182
+ 1. If an incompatible API (code) change is made, the MAJOR version will be
183
+ incremented, MINOR will be set to zero, and PATCH will be reset to the
184
+ implied zero.
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.
189
+
190
+ 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.
8
199
 
9
- MIME::Types for Ruby originally based on and synchronized with MIME::Types for
10
- Perl by Mark Overmeer, copyright 2001 - 2009. As of version 1.15, the data
11
- format for the MIME::Type list has changed and the synchronization will no
12
- longer happen.
200
+ :include: Code-of-Conduct.rdoc
13
201
 
14
- Homepage:: http://mime-types.rubyforge.org/
15
- GitHub:: http://github.com/halostatue/mime-types/
16
- Copyright:: 2002 - 2011, Austin Ziegler
17
- Based in part on prior work copyright Mark Overmeer
202
+ :include: Contributing.rdoc
18
203
 
19
- :include: License.rdoc
204
+ :include: Licence.rdoc
data/Rakefile CHANGED
@@ -2,197 +2,219 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
+ require 'rake/clean'
5
6
 
6
7
  Hoe.plugin :doofus
7
- Hoe.plugin :gemspec
8
- Hoe.plugin :rubyforge
8
+ Hoe.plugin :gemspec2
9
9
  Hoe.plugin :git
10
10
  Hoe.plugin :minitest
11
+ Hoe.plugin :travis
12
+ Hoe.plugin :email unless ENV['CI'] or ENV['TRAVIS']
11
13
 
12
14
  spec = Hoe.spec 'mime-types' do
13
- self.rubyforge_name = self.name
15
+ developer('Austin Ziegler', 'halostatue@gmail.com')
16
+ self.need_tar = true
14
17
 
15
- developer('Austin Ziegler', 'austin@rubyforge.org')
16
-
17
- self.url = "http://mime-types.rubyforge.org/"
18
- self.remote_rdoc_dir = 'rdoc'
19
- self.rsync_args << ' --exclude=statsvn/'
18
+ require_ruby_version '>= 2.0'
20
19
 
21
20
  self.history_file = 'History.rdoc'
22
21
  self.readme_file = 'README.rdoc'
23
- self.extra_rdoc_files = FileList["*.rdoc"].to_a
24
-
25
- self.extra_dev_deps << ['nokogiri', '~> 1.5']
26
- self.extra_dev_deps << ['minitest', '~> 2.0']
27
- self.extra_dev_deps << ['hoe-doofus', '~> 1.0']
28
- self.extra_dev_deps << ['hoe-gemspec', '~> 1.0']
29
- self.extra_dev_deps << ['hoe-git', '~> 1.0']
30
- self.extra_dev_deps << ['hoe-seattlerb', '~> 1.0']
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', '~> 2.0']
36
+ extra_dev_deps << ['rake', '~> 10.0']
37
+ extra_dev_deps << ['fivemat', '~> 1.3' ]
38
+ extra_dev_deps << ['minitest-rg', '~> 5.2']
39
+
40
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.0')
41
+ extra_dev_deps << ['simplecov', '~> 0.7']
42
+ # if ENV['CI'] or ENV['TRAVIS']
43
+ # extra_dev_deps << ['coveralls', '~> 0.8']
44
+ # end
45
+ end
31
46
  end
32
47
 
33
- namespace :mime do
34
- desc "Download the current MIME type registrations from IANA."
35
- task :iana, :save, :destination do |t, args|
36
- save_type = (args.save || :text).to_sym
48
+ namespace :benchmark do
49
+ task :support do
50
+ %w(lib support).each { |path|
51
+ $LOAD_PATH.unshift(File.join(Rake.application.original_dir, path))
52
+ }
53
+ end
37
54
 
38
- case save_type
39
- when :text, :both, :html
40
- nil
41
- else
42
- raise "Unknown save type provided. Must be one of text, both, or html."
43
- end
55
+ desc 'Benchmark Load Times'
56
+ task :load, [ :repeats ] => 'benchmark:support' do |_, args|
57
+ require 'benchmarks/load'
58
+ Benchmarks::Load.report(
59
+ File.join(Rake.application.original_dir, 'lib'),
60
+ args.repeats
61
+ )
62
+ end
44
63
 
45
- destination = args.destination || "type-lists"
64
+ desc 'Allocation counts'
65
+ task :allocations, [ :top_x, :mime_types_only ] => 'benchmark:support' do |_, args|
66
+ require 'benchmarks/load_allocations'
67
+ Benchmarks::LoadAllocations.report(
68
+ top_x: args.top_x,
69
+ mime_types_only: args.mime_types_only
70
+ )
71
+ end
46
72
 
47
- require 'open-uri'
48
- require 'nokogiri'
49
- require 'cgi'
73
+ desc 'Columnar allocation counts'
74
+ task 'allocations:columnar', [ :top_x, :mime_types_only ] => 'benchmark:support' do |_, args|
75
+ require 'benchmarks/load_allocations'
76
+ Benchmarks::LoadAllocations.report(
77
+ columnar: true,
78
+ top_x: args.top_x,
79
+ mime_types_only: args.mime_types_only
80
+ )
81
+ end
50
82
 
51
- class IANAParser
52
- include Comparable
83
+ desc 'Columnar allocation counts (full load)'
84
+ task 'allocations:columnar:full', [ :top_x, :mime_types_only ] => 'benchmark:support' do |_, args|
85
+ require 'benchmarks/load_allocations'
86
+ Benchmarks::LoadAllocations.report(
87
+ columnar: true,
88
+ top_x: args.top_x,
89
+ mime_types_only: args.mime_types_only,
90
+ full: true
91
+ )
92
+ end
53
93
 
54
- INDEX = %q(http://www.iana.org/assignments/media-types/)
55
- CONTACT_PEOPLE = %r{http://www.iana.org/assignments/contact-people.html?#(.*)}
56
- RFC_EDITOR = %r{http://www.rfc-editor.org/rfc/rfc(\d+).txt}
57
- IETF_RFC = %r{http://www.ietf.org/rfc/rfc(\d+).txt}
58
- IETF_RFC_TOOLS = %r{http://tools.ietf.org/html/rfc(\d+)}
94
+ desc 'Object counts'
95
+ task objects: 'benchmark:support' do
96
+ require 'benchmarks/object_counts'
97
+ Benchmarks::ObjectCounts.report
98
+ end
59
99
 
60
- class << self
61
- def load_index
62
- @types ||= {}
100
+ desc 'Columnar object counts'
101
+ task 'objects:columnar' => 'benchmark:support' do
102
+ require 'benchmarks/object_counts'
103
+ Benchmarks::ObjectCounts.report(columnar: true)
104
+ end
63
105
 
64
- Nokogiri::HTML(open(INDEX) { |f| f.read }).xpath('//p/a').each do |tag|
65
- href_match = %r{^/assignments/media-types/(.+)/$}.match(tag['href'])
66
- next if href_match.nil?
67
- type = href_match.captures[0]
68
- @types[tag.content] = IANAParser.new(tag.content, type)
69
- end
70
- end
106
+ desc 'Columnar object counts (full load)'
107
+ task 'objects:columnar:full' => 'benchmark:support' do
108
+ require 'benchmarks/object_counts'
109
+ Benchmarks::ObjectCounts.report(columnar: true, full: true)
110
+ end
111
+ end
71
112
 
72
- attr_reader :types
73
- end
113
+ namespace :profile do
114
+ directory 'tmp/profile'
115
+
116
+ CLEAN.add 'tmp'
117
+
118
+ def ruby_prof(script)
119
+ require 'pathname'
120
+ output = Pathname('tmp/profile').join(script)
121
+ output.mkpath
122
+ script = Pathname('support/profile').join("#{script}.rb")
123
+
124
+ args = [
125
+ '-W0',
126
+ '-Ilib',
127
+ '-S', 'ruby-prof',
128
+ '-R', 'mime/types',
129
+ '-s', 'self',
130
+ '-p', 'multi',
131
+ '-f', "#{output}",
132
+ script.to_s
133
+ ]
134
+ ruby args.join(' ')
135
+ end
74
136
 
75
- def initialize(name, type)
76
- @name = name
77
- @type = type
78
- @url = File.join(INDEX, @type)
79
- end
137
+ task full: 'tmp/profile' do
138
+ ruby_prof 'full'
139
+ end
80
140
 
81
- attr_reader :name
82
- attr_reader :type
83
- attr_reader :url
84
- attr_reader :html
141
+ task columnar: :support do
142
+ ruby_prof 'columnar'
143
+ end
85
144
 
86
- def download(name = nil)
87
- @html = Nokogiri::HTML(open(name || @url) { |f| f.read })
88
- end
145
+ task 'columnar:full' => :support do
146
+ ruby_prof 'columnar_full'
147
+ end
148
+ end
89
149
 
90
- def save_html
91
- File.open("#@name.html", "wb") { |w| w.write @html }
92
- end
150
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.0')
151
+ namespace :test do
152
+ # Coveralls needs to be disabled for now because it transitively depends on
153
+ # an earlier version of mime-types.
154
+ # if ENV['CI'] or ENV['TRAVIS']
155
+ # task :coveralls do
156
+ # spec.test_prelude = [
157
+ # 'require "psych"',
158
+ # 'require "simplecov"',
159
+ # 'require "coveralls"',
160
+ # 'SimpleCov.formatter = Coveralls::SimpleCov::Formatter',
161
+ # 'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
162
+ # 'gem "minitest"'
163
+ # ].join('; ')
164
+ # Rake::Task['test'].execute
165
+ # end
166
+
167
+ # Rake::Task['travis'].prerequisites.replace(%w(test:coveralls))
168
+ # end
169
+
170
+ desc 'Run test coverage'
171
+ task :coverage do
172
+ spec.test_prelude = [
173
+ 'require "simplecov"',
174
+ 'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
175
+ 'gem "minitest"'
176
+ ].join('; ')
177
+ Rake::Task['test'].execute
178
+ end
179
+ end
180
+ end
93
181
 
94
- def <=>(o)
95
- self.name <=> o.name
96
- end
182
+ namespace :convert do
183
+ namespace :docs do
184
+ task :setup do
185
+ gem 'rdoc'
186
+ require 'rdoc/rdoc'
187
+ @doc_converter ||= RDoc::Markup::ToMarkdown.new
188
+ end
97
189
 
98
- def parse
99
- nodes = html.xpath("//table//table//tr")
100
-
101
- # How many <td> children does the first node have?
102
- node_count = nodes.first.children.select { |n| n.elem? }.size
103
-
104
- if node_count == 1
105
- # The title node doesn't have what we expect. Let's try it based
106
- # on the first real node.
107
- node_count = nodes.first.next.children.select { |n| n.elem? }.size
108
- end
109
-
110
- @mime_types = nodes.map do |node|
111
- next if node == nodes.first
112
- elems = node.children.select { |n| n.elem? }
113
- next if elems.size.zero?
114
-
115
- raise "size mismatch #{elems.size} != #{node_count}" if node_count != elems.size
116
-
117
- case elems.size
118
- when 3
119
- subtype_index = 1
120
- refnode_index = 2
121
- when 4
122
- subtype_index = 1
123
- refnode_index = 3
124
- else
125
- raise "Unknown element size."
126
- end
127
-
128
- subtype = elems[subtype_index].content.chomp.strip
129
- refnodes = elems[refnode_index].children.select { |n| n.elem? }.map { |ref|
130
- case ref['href']
131
- when CONTACT_PEOPLE
132
- tag = CGI::unescape($1).chomp.strip
133
- if tag == ref.content
134
- "[#{ref.content}]"
135
- else
136
- "[#{ref.content}=#{tag}]"
137
- end
138
- when RFC_EDITOR, IETF_RFC, IETF_RFC_TOOLS
139
- "RFC#$1"
140
- when %r{(https?://.*)}
141
- "{#{ref.content}=#$1}"
142
- else
143
- ref
144
- end
145
- }
146
- refs = refnodes.join(',')
147
-
148
- "#@type/#{subtype} 'IANA,#{refs}"
149
- end.compact
150
-
151
- @mime_types
152
- end
190
+ FileList['*.rdoc'].each do |name|
191
+ rdoc = "#{name}.rdoc"
192
+ mark = "#{name}.md"
153
193
 
154
- def save_text
155
- File.open("#@name.txt", "wb") { |w| w.write @mime_types.join("\n") }
194
+ file mark => [ rdoc, :setup ] do |t|
195
+ puts "#{rdoc} => #{mark}"
196
+ File.open(t.name, 'wb') { |target|
197
+ target.write @doc_converter.convert(IO.read(t.prerequisites.first))
198
+ }
156
199
  end
157
- end
158
200
 
159
- puts "Downloading index of MIME types from #{IANAParser::INDEX}."
160
- IANAParser.load_index
161
-
162
- require 'fileutils'
163
- FileUtils.mkdir_p destination
164
- Dir.chdir destination do
165
- IANAParser.types.values.sort.each do |parser|
166
- next if parser.name == "example" or parser.name == "mime"
167
- puts "Downloading #{parser.name} from #{parser.url}"
168
- parser.download
169
-
170
- if :html == save_type || :both == save_type
171
- puts "Saving #{parser.name}.html"
172
- parser.save_html
173
- end
174
-
175
- puts "Parsing #{parser.name} HTML"
176
- parser.parse
177
-
178
- if :text == save_type || :both == save_type
179
- puts "Saving #{parser.name}.txt"
180
- parser.save_text
181
- end
182
- end
201
+ CLEAN.add mark
202
+
203
+ task run: [ mark ]
183
204
  end
184
205
  end
185
206
 
186
- desc "Shows known MIME type sources."
187
- task :mime_type_sources do
188
- puts <<-EOS
189
- http://www.ltsw.se/knbase/internet/mime.htp
190
- http://www.webmaster-toolkit.com/mime-types.shtml
191
- http://plugindoc.mozdev.org/winmime.php
192
- http://standards.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html
193
- http://www.feedforall.com/mime-types.htm
194
- http://www.iana.org/assignments/media-types/
195
- EOS
207
+ desc 'Convert documentation from RDoc to Markdown'
208
+ task docs: 'convert:docs:run'
209
+ end
210
+
211
+ task :console do
212
+ arguments = %w(pry)
213
+ arguments.push(*spec.spec.require_paths.map { |dir| "-I#{dir}" })
214
+ arguments.push("-r#{spec.spec.name.gsub('-', File::SEPARATOR)}")
215
+ unless system(*arguments)
216
+ error "Command failed: #{show_command}"
217
+ abort
196
218
  end
197
219
  end
198
220