mime-types 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Code-of-Conduct.md +73 -0
- data/Contributing.md +143 -0
- data/History.md +240 -0
- data/Licence.md +25 -0
- data/Manifest.txt +31 -0
- data/README.rdoc +193 -0
- data/Rakefile +284 -0
- data/lib/mime-types.rb +3 -0
- data/lib/mime/type.rb +587 -0
- data/lib/mime/type/columnar.rb +57 -0
- data/lib/mime/types.rb +231 -0
- data/lib/mime/types/_columnar.rb +136 -0
- data/lib/mime/types/cache.rb +58 -0
- data/lib/mime/types/columnar.rb +3 -0
- data/lib/mime/types/container.rb +96 -0
- data/lib/mime/types/deprecations.rb +32 -0
- data/lib/mime/types/full.rb +19 -0
- data/lib/mime/types/loader.rb +146 -0
- data/lib/mime/types/logger.rb +39 -0
- data/lib/mime/types/registry.rb +90 -0
- data/test/bad-fixtures/malformed +9 -0
- data/test/fixture/json.json +1 -0
- data/test/fixture/old-data +9 -0
- data/test/fixture/yaml.yaml +55 -0
- data/test/minitest_helper.rb +13 -0
- data/test/test_mime_type.rb +610 -0
- data/test/test_mime_types.rb +169 -0
- data/test/test_mime_types_cache.rb +118 -0
- data/test/test_mime_types_class.rb +159 -0
- data/test/test_mime_types_lazy.rb +49 -0
- data/test/test_mime_types_loader.rb +32 -0
- metadata +349 -0
data/Licence.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## Licence
|
2
|
+
|
3
|
+
* Copyright 2003–2019 Austin Ziegler and contributors.
|
4
|
+
|
5
|
+
The software in this repository is made available under the MIT license.
|
6
|
+
|
7
|
+
### MIT License
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
10
|
+
this software and associated documentation files (the "Software"), to deal in
|
11
|
+
the Software without restriction, including without limitation the rights to
|
12
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
13
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
14
|
+
so, subject to the following conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
17
|
+
copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
25
|
+
SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Code-of-Conduct.md
|
2
|
+
Contributing.md
|
3
|
+
History.md
|
4
|
+
Licence.md
|
5
|
+
Manifest.txt
|
6
|
+
README.rdoc
|
7
|
+
Rakefile
|
8
|
+
lib/mime-types.rb
|
9
|
+
lib/mime/type.rb
|
10
|
+
lib/mime/type/columnar.rb
|
11
|
+
lib/mime/types.rb
|
12
|
+
lib/mime/types/_columnar.rb
|
13
|
+
lib/mime/types/cache.rb
|
14
|
+
lib/mime/types/columnar.rb
|
15
|
+
lib/mime/types/container.rb
|
16
|
+
lib/mime/types/deprecations.rb
|
17
|
+
lib/mime/types/full.rb
|
18
|
+
lib/mime/types/loader.rb
|
19
|
+
lib/mime/types/logger.rb
|
20
|
+
lib/mime/types/registry.rb
|
21
|
+
test/bad-fixtures/malformed
|
22
|
+
test/fixture/json.json
|
23
|
+
test/fixture/old-data
|
24
|
+
test/fixture/yaml.yaml
|
25
|
+
test/minitest_helper.rb
|
26
|
+
test/test_mime_type.rb
|
27
|
+
test/test_mime_types.rb
|
28
|
+
test/test_mime_types_cache.rb
|
29
|
+
test/test_mime_types_class.rb
|
30
|
+
test/test_mime_types_lazy.rb
|
31
|
+
test/test_mime_types_loader.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,193 @@
|
|
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
|
+
clog :: https://github.com/mime-types/ruby-mime-types/blob/master/History.md
|
8
|
+
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]
|
9
|
+
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]
|
10
|
+
|
11
|
+
== Description
|
12
|
+
|
13
|
+
The mime-types library provides a library and registry for information about
|
14
|
+
MIME content type definitions. It can be used to determine defined filename
|
15
|
+
extensions for MIME types, or to use filename extensions to look up the likely
|
16
|
+
MIME type definitions.
|
17
|
+
|
18
|
+
Version 3.0 is a major release that requires Ruby 2.0 compatibility and removes
|
19
|
+
deprecated functions. The columnar registry format introduced in 2.6 has been
|
20
|
+
made the primary format; the registry data has been extracted from this library
|
21
|
+
and put into {mime-types-data}[https://github.com/mime-types/mime-types-data].
|
22
|
+
Additionally, mime-types is now licensed exclusively under the MIT licence and
|
23
|
+
there is a code of conduct in effect. There are a number of other smaller
|
24
|
+
changes described in the History file.
|
25
|
+
|
26
|
+
=== About MIME Media Types
|
27
|
+
|
28
|
+
MIME content types are used in MIME-compliant communications, as in e-mail or
|
29
|
+
HTTP traffic, to indicate the type of content which is transmitted. The
|
30
|
+
mime-types library provides the ability for detailed information about MIME
|
31
|
+
entities (provided as an enumerable collection of MIME::Type objects) to be
|
32
|
+
determined and used. There are many types defined by RFCs and vendors, so the
|
33
|
+
list is long but by definition incomplete; don't hesitate to add additional
|
34
|
+
type definitions. MIME type definitions found in mime-types are from RFCs, W3C
|
35
|
+
recommendations, the {IANA Media Types
|
36
|
+
registry}[https://www.iana.org/assignments/media-types/media-types.xhtml], and
|
37
|
+
user contributions. It conforms to RFCs 2045 and 2231.
|
38
|
+
|
39
|
+
=== mime-types 3.x
|
40
|
+
|
41
|
+
Users are encouraged to upgrade to mime-types 3.x as soon as is practical.
|
42
|
+
mime-types 3.x requires Ruby 2.0 compatibility and a simpler licensing scheme.
|
43
|
+
|
44
|
+
== Synopsis
|
45
|
+
|
46
|
+
MIME types are used in MIME entities, as in email or HTTP traffic. It is useful
|
47
|
+
at times to have information available about MIME types (or, inversely, about
|
48
|
+
files). A MIME::Type stores the known information about one MIME type.
|
49
|
+
|
50
|
+
require 'mime/types'
|
51
|
+
|
52
|
+
plaintext = MIME::Types['text/plain'] # => [ text/plain ]
|
53
|
+
text = plaintext.first
|
54
|
+
puts text.media_type # => 'text'
|
55
|
+
puts text.sub_type # => 'plain'
|
56
|
+
|
57
|
+
puts text.extensions.join(' ') # => 'txt asc c cc h hh cpp hpp dat hlp'
|
58
|
+
puts text.preferred_extension # => 'txt'
|
59
|
+
puts text.friendly # => 'Text Document'
|
60
|
+
puts text.i18n_key # => 'text.plain'
|
61
|
+
|
62
|
+
puts text.encoding # => quoted-printable
|
63
|
+
puts text.default_encoding # => quoted-printable
|
64
|
+
puts text.binary? # => false
|
65
|
+
puts text.ascii? # => true
|
66
|
+
puts text.obsolete? # => false
|
67
|
+
puts text.registered? # => true
|
68
|
+
puts text.complete? # => true
|
69
|
+
|
70
|
+
puts text # => 'text/plain'
|
71
|
+
|
72
|
+
puts text == 'text/plain' # => true
|
73
|
+
puts 'text/plain' == text # => true
|
74
|
+
puts text == 'text/x-plain' # => false
|
75
|
+
puts 'text/x-plain' == text # => false
|
76
|
+
|
77
|
+
puts MIME::Type.simplified('x-appl/x-zip') # => 'x-appl/x-zip'
|
78
|
+
puts MIME::Type.i18n_key('x-appl/x-zip') # => 'x-appl.x-zip'
|
79
|
+
|
80
|
+
puts text.like?('text/x-plain') # => true
|
81
|
+
puts text.like?(MIME::Type.new('x-text/x-plain')) # => true
|
82
|
+
|
83
|
+
puts text.xrefs.inspect # => { "rfc" => [ "rfc2046", "rfc3676", "rfc5147" ] }
|
84
|
+
puts text.xref_urls # => [ "http://www.iana.org/go/rfc2046",
|
85
|
+
# "http://www.iana.org/go/rfc3676",
|
86
|
+
# "http://www.iana.org/go/rfc5147" ]
|
87
|
+
|
88
|
+
xtext = MIME::Type.new('x-text/x-plain')
|
89
|
+
puts xtext.media_type # => 'text'
|
90
|
+
puts xtext.raw_media_type # => 'x-text'
|
91
|
+
puts xtext.sub_type # => 'plain'
|
92
|
+
puts xtext.raw_sub_type # => 'x-plain'
|
93
|
+
puts xtext.complete? # => false
|
94
|
+
|
95
|
+
puts MIME::Types.any? { |type| type.content_type == 'text/plain' } # => true
|
96
|
+
puts MIME::Types.all?(&:registered?) # => false
|
97
|
+
|
98
|
+
# Various string representations of MIME types
|
99
|
+
qcelp = MIME::Types['audio/QCELP'].first # => audio/QCELP
|
100
|
+
puts qcelp.content_type # => 'audio/QCELP'
|
101
|
+
puts qcelp.simplified # => 'audio/qcelp'
|
102
|
+
|
103
|
+
xwingz = MIME::Types['application/x-Wingz'].first # => application/x-Wingz
|
104
|
+
puts xwingz.content_type # => 'application/x-Wingz'
|
105
|
+
puts xwingz.simplified # => 'application/x-wingz'
|
106
|
+
|
107
|
+
=== Columnar Store
|
108
|
+
|
109
|
+
mime-types uses as its primary registry storage format a columnar storage
|
110
|
+
format reducing the default memory footprint. This is done by selectively
|
111
|
+
loading the data on a per-attribute basis. When the registry is first loaded
|
112
|
+
from the columnar store, only the canonical MIME content type and known
|
113
|
+
extensions and the MIME type will be connected to its loading registry. When
|
114
|
+
other data about the type is required (including +preferred_extension+,
|
115
|
+
<tt>obsolete?</tt>, and <tt>registered?</tt>) that data is loaded from its own
|
116
|
+
column file for all types in the registry.
|
117
|
+
|
118
|
+
The load of any column data is performed with a Mutex to ensure that types are
|
119
|
+
updated safely in a multithreaded environment. Benchmarks show that while
|
120
|
+
columnar data loading is slower than the JSON store, it cuts the memory use by
|
121
|
+
a third over the JSON store.
|
122
|
+
|
123
|
+
If you prefer to load all the data at once, this can be specified in your
|
124
|
+
application Gemfile as:
|
125
|
+
|
126
|
+
gem 'mime-types', require: 'mime/types/full'
|
127
|
+
|
128
|
+
Projects that do not use Bundler should +require+ the same:
|
129
|
+
|
130
|
+
require 'mime/types/full'
|
131
|
+
|
132
|
+
Libraries that use mime-types are discouraged from choosing the JSON store.
|
133
|
+
|
134
|
+
For applications and clients that used mime-types 2.6 when the columnar store
|
135
|
+
was introduced, the require used previously will still work through at least
|
136
|
+
{version
|
137
|
+
4}[https://github.com/mime-types/ruby-mime-types/pull/96#issuecomment-100725400]
|
138
|
+
and possibly beyond; it is effectively an empty operation. You are recommended
|
139
|
+
to change your Gemfile as soon as is practical.
|
140
|
+
|
141
|
+
require 'mime/types/columnar'
|
142
|
+
|
143
|
+
Note that MIME::Type::Columnar and MIME::Types::Columnar are considered private
|
144
|
+
variant implementations of MIME::Type and MIME::Types and the specific
|
145
|
+
implementation should not be relied upon by consumers of the mime-types
|
146
|
+
library. Instead, depend on the public implementations (MIME::Type and
|
147
|
+
MIME::Types) only.
|
148
|
+
|
149
|
+
=== Cached Storage
|
150
|
+
|
151
|
+
mime-types supports a cache of MIME types using <tt>Marshal.dump</tt>. The
|
152
|
+
cache is invalidated for each version of the mime-types-data gem so that data
|
153
|
+
version 3.2015.1201 will not be reused with data version 3.2016.0101. If the
|
154
|
+
environment variable +RUBY_MIME_TYPES_CACHE+ is set to a cache file, mime-types
|
155
|
+
will attempt to load the MIME type registry from the cache file. If it cannot,
|
156
|
+
it will load the types normally and then saves the registry to the cache file.
|
157
|
+
|
158
|
+
The caching works with both full stores and columnar stores. Only the data that
|
159
|
+
has been loaded prior to saving the cache will be stored.
|
160
|
+
|
161
|
+
== mime-types Modified Semantic Versioning
|
162
|
+
|
163
|
+
The mime-types library has one version number, but this single version number
|
164
|
+
tracks both API changes and registry data changes; this is not wholly
|
165
|
+
compatible with all aspects of {Semantic Versioning}[http://semver.org/];
|
166
|
+
removing a MIME type from the registry *could* be considered a breaking change
|
167
|
+
under some interpretations of semantic versioning (as lookups for that
|
168
|
+
particular type would no longer work by default).
|
169
|
+
|
170
|
+
mime-types uses a modified semantic versioning scheme. Given the version
|
171
|
+
MAJOR.MINOR:
|
172
|
+
|
173
|
+
1. If an incompatible API (code) change is made, the MAJOR version will be
|
174
|
+
incremented, MINOR will be set to zero, and PATCH will be reset to the
|
175
|
+
implied zero.
|
176
|
+
|
177
|
+
2. If an API (code) feature is added that does not break compatibility, the
|
178
|
+
MINOR version will be incremented and PATCH will be reset to the implied zero.
|
179
|
+
|
180
|
+
3. If there is a bugfix to a feature added in the most recent MAJOR.MINOR
|
181
|
+
release, the implied PATCH value will be incremented resulting in
|
182
|
+
MAJOR.MINOR.PATCH.
|
183
|
+
|
184
|
+
In practical terms, there will be fewer releases of mime-types focussing on
|
185
|
+
features because of the existence of the [mime-types-data][] gem, and if
|
186
|
+
features are marked deprecated in the course of mime-types 3.x, they will not
|
187
|
+
be removed until mime-types 4.x or possibly later.
|
188
|
+
|
189
|
+
{Code of Conduct}[Code-of-Conduct_md.html]
|
190
|
+
|
191
|
+
{Contributing}[Contributing_md.html]
|
192
|
+
|
193
|
+
{Licence}[Licence_md.html]
|
data/Rakefile
ADDED
@@ -0,0 +1,284 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require 'rake/clean'
|
6
|
+
|
7
|
+
Hoe.plugin :doofus
|
8
|
+
Hoe.plugin :gemspec2
|
9
|
+
Hoe.plugin :git
|
10
|
+
Hoe.plugin :minitest
|
11
|
+
Hoe.plugin :travis
|
12
|
+
Hoe.plugin :email unless ENV['CI'] or ENV['TRAVIS']
|
13
|
+
|
14
|
+
spec = Hoe.spec 'mime-types' do
|
15
|
+
developer('Austin Ziegler', 'halostatue@gmail.com')
|
16
|
+
self.need_tar = true
|
17
|
+
|
18
|
+
require_ruby_version '>= 2.0'
|
19
|
+
|
20
|
+
self.history_file = 'History.md'
|
21
|
+
self.readme_file = 'README.rdoc'
|
22
|
+
|
23
|
+
license 'MIT'
|
24
|
+
|
25
|
+
extra_deps << ['mime-types-data', '~> 3.2015']
|
26
|
+
|
27
|
+
extra_dev_deps << ['hoe-doofus', '~> 1.0']
|
28
|
+
extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
|
29
|
+
extra_dev_deps << ['hoe-git', '~> 1.6']
|
30
|
+
extra_dev_deps << ['hoe-rubygems', '~> 1.0']
|
31
|
+
extra_dev_deps << ['hoe-travis', '~> 1.2']
|
32
|
+
extra_dev_deps << ['minitest', '~> 5.4']
|
33
|
+
extra_dev_deps << ['minitest-autotest', '~> 1.0']
|
34
|
+
extra_dev_deps << ['minitest-focus', '~> 1.0']
|
35
|
+
extra_dev_deps << ['minitest-bonus-assertions', '~> 3.0']
|
36
|
+
extra_dev_deps << ['minitest-hooks', '~> 1.4']
|
37
|
+
extra_dev_deps << ['rake', '>= 10.0', '< 13.0']
|
38
|
+
extra_dev_deps << ['fivemat', '~> 1.3']
|
39
|
+
extra_dev_deps << ['minitest-rg', '~> 5.2']
|
40
|
+
|
41
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.0')
|
42
|
+
extra_dev_deps << ['simplecov', '~> 0.7']
|
43
|
+
# if ENV['CI'] or ENV['TRAVIS']
|
44
|
+
# extra_dev_deps << ['coveralls', '~> 0.8']
|
45
|
+
# end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
namespace :benchmark do
|
50
|
+
task :support do
|
51
|
+
%w(lib support).each { |path|
|
52
|
+
$LOAD_PATH.unshift(File.join(Rake.application.original_dir, path))
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
desc 'Benchmark Load Times'
|
57
|
+
task :load, [:repeats] => 'benchmark:support' do |_, args|
|
58
|
+
require 'benchmarks/load'
|
59
|
+
Benchmarks::Load.report(
|
60
|
+
File.join(Rake.application.original_dir, 'lib'),
|
61
|
+
args.repeats
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
desc 'Allocation counts'
|
66
|
+
task :allocations, [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
|
67
|
+
require 'benchmarks/load_allocations'
|
68
|
+
Benchmarks::LoadAllocations.report(
|
69
|
+
top_x: args.top_x,
|
70
|
+
mime_types_only: args.mime_types_only
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
desc 'Columnar allocation counts'
|
75
|
+
task 'allocations:columnar', [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
|
76
|
+
require 'benchmarks/load_allocations'
|
77
|
+
Benchmarks::LoadAllocations.report(
|
78
|
+
columnar: true,
|
79
|
+
top_x: args.top_x,
|
80
|
+
mime_types_only: args.mime_types_only
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
desc 'Columnar allocation counts (full load)'
|
85
|
+
task 'allocations:columnar:full', [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
|
86
|
+
require 'benchmarks/load_allocations'
|
87
|
+
Benchmarks::LoadAllocations.report(
|
88
|
+
columnar: true,
|
89
|
+
top_x: args.top_x,
|
90
|
+
mime_types_only: args.mime_types_only,
|
91
|
+
full: true
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
desc 'Memory profiler'
|
96
|
+
task :memory, [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
|
97
|
+
require 'benchmarks/memory_profiler'
|
98
|
+
Benchmarks::ProfileMemory.report(
|
99
|
+
mime_types_only: args.mime_types_only,
|
100
|
+
top_x: args.top_x
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
desc 'Columnar memory profiler'
|
105
|
+
task 'memory:columnar', [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
|
106
|
+
require 'benchmarks/memory_profiler'
|
107
|
+
Benchmarks::ProfileMemory.report(
|
108
|
+
columnar: true,
|
109
|
+
mime_types_only: args.mime_types_only,
|
110
|
+
top_x: args.top_x
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
desc 'Columnar allocation counts (full load)'
|
115
|
+
task 'memory:columnar:full', [:top_x, :mime_types_only] => 'benchmark:support' do |_, args|
|
116
|
+
require 'benchmarks/memory_profiler'
|
117
|
+
Benchmarks::ProfileMemory.report(
|
118
|
+
columnar: true,
|
119
|
+
full: true,
|
120
|
+
top_x: args.top_x,
|
121
|
+
mime_types_only: args.mime_types_only
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
desc 'Object counts'
|
126
|
+
task objects: 'benchmark:support' do
|
127
|
+
require 'benchmarks/object_counts'
|
128
|
+
Benchmarks::ObjectCounts.report
|
129
|
+
end
|
130
|
+
|
131
|
+
desc 'Columnar object counts'
|
132
|
+
task 'objects:columnar' => 'benchmark:support' do
|
133
|
+
require 'benchmarks/object_counts'
|
134
|
+
Benchmarks::ObjectCounts.report(columnar: true)
|
135
|
+
end
|
136
|
+
|
137
|
+
desc 'Columnar object counts (full load)'
|
138
|
+
task 'objects:columnar:full' => 'benchmark:support' do
|
139
|
+
require 'benchmarks/object_counts'
|
140
|
+
Benchmarks::ObjectCounts.report(columnar: true, full: true)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
namespace :profile do
|
145
|
+
directory 'tmp/profile'
|
146
|
+
|
147
|
+
CLEAN.add 'tmp'
|
148
|
+
|
149
|
+
def ruby_prof(script)
|
150
|
+
require 'pathname'
|
151
|
+
output = Pathname('tmp/profile').join(script)
|
152
|
+
output.mkpath
|
153
|
+
script = Pathname('support/profile').join("#{script}.rb")
|
154
|
+
|
155
|
+
args = [
|
156
|
+
'-W0',
|
157
|
+
'-Ilib',
|
158
|
+
'-S', 'ruby-prof',
|
159
|
+
'-R', 'mime/types',
|
160
|
+
'-s', 'self',
|
161
|
+
'-p', 'multi',
|
162
|
+
'-f', output.to_s,
|
163
|
+
script.to_s
|
164
|
+
]
|
165
|
+
ruby args.join(' ')
|
166
|
+
end
|
167
|
+
|
168
|
+
task full: 'tmp/profile' do
|
169
|
+
ruby_prof 'full'
|
170
|
+
end
|
171
|
+
|
172
|
+
task columnar: :support do
|
173
|
+
ruby_prof 'columnar'
|
174
|
+
end
|
175
|
+
|
176
|
+
task 'columnar:full' => :support do
|
177
|
+
ruby_prof 'columnar_full'
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.0')
|
182
|
+
namespace :test do
|
183
|
+
# Coveralls needs to be disabled for now because it transitively depends on
|
184
|
+
# an earlier version of mime-types.
|
185
|
+
# if ENV['CI'] or ENV['TRAVIS']
|
186
|
+
# task :coveralls do
|
187
|
+
# spec.test_prelude = [
|
188
|
+
# 'require "psych"',
|
189
|
+
# 'require "simplecov"',
|
190
|
+
# 'require "coveralls"',
|
191
|
+
# 'SimpleCov.formatter = Coveralls::SimpleCov::Formatter',
|
192
|
+
# 'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
|
193
|
+
# 'gem "minitest"'
|
194
|
+
# ].join('; ')
|
195
|
+
# Rake::Task['test'].execute
|
196
|
+
# end
|
197
|
+
|
198
|
+
# Rake::Task['travis'].prerequisites.replace(%w(test:coveralls))
|
199
|
+
# end
|
200
|
+
|
201
|
+
desc 'Run test coverage'
|
202
|
+
task :coverage do
|
203
|
+
spec.test_prelude = [
|
204
|
+
'require "simplecov"',
|
205
|
+
'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
|
206
|
+
'gem "minitest"'
|
207
|
+
].join('; ')
|
208
|
+
Rake::Task['test'].execute
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
namespace :convert do
|
214
|
+
namespace :docs do
|
215
|
+
task :setup do
|
216
|
+
gem 'rdoc'
|
217
|
+
require 'rdoc/rdoc'
|
218
|
+
@doc_converter ||= RDoc::Markup::ToMarkdown.new
|
219
|
+
end
|
220
|
+
|
221
|
+
FileList['*.rdoc'].each do |name|
|
222
|
+
rdoc = name
|
223
|
+
mark = "#{File.basename(name, '.rdoc')}.md"
|
224
|
+
|
225
|
+
file mark => [rdoc, :setup] do |t|
|
226
|
+
puts "#{rdoc} => #{mark}"
|
227
|
+
File.open(t.name, 'wb') { |target|
|
228
|
+
target.write @doc_converter.convert(IO.read(t.prerequisites.first))
|
229
|
+
}
|
230
|
+
end
|
231
|
+
|
232
|
+
CLEAN.add mark
|
233
|
+
|
234
|
+
task run: [mark]
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
desc 'Convert documentation from RDoc to Markdown'
|
239
|
+
task docs: 'convert:docs:run'
|
240
|
+
end
|
241
|
+
|
242
|
+
task 'deps:top', [:number] do |_, args|
|
243
|
+
require 'net/http'
|
244
|
+
require 'json'
|
245
|
+
|
246
|
+
def rubygems_get(gem_name: '', endpoint: '')
|
247
|
+
path = File.join('/api/v1/gems/', gem_name, endpoint).chomp('/') + '.json'
|
248
|
+
Net::HTTP.start('rubygems.org', use_ssl: true) do |http|
|
249
|
+
JSON.parse(http.get(path).body)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
results = rubygems_get(
|
254
|
+
gem_name: 'mime-types',
|
255
|
+
endpoint: 'reverse_dependencies'
|
256
|
+
)
|
257
|
+
|
258
|
+
weighted_results = {}
|
259
|
+
results.each do |name|
|
260
|
+
begin
|
261
|
+
weighted_results[name] = rubygems_get(gem_name: name)['downloads']
|
262
|
+
rescue => e
|
263
|
+
puts "#{name} #{e.message}"
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
weighted_results.sort { |(_k1, v1), (_k2, v2)|
|
268
|
+
v2 <=> v1
|
269
|
+
}.first(args.number || 50).each_with_index do |(k, v), i|
|
270
|
+
puts "#{i}) #{k}: #{v}"
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
task :console do
|
275
|
+
arguments = %w(pry)
|
276
|
+
arguments.push(*spec.spec.require_paths.map { |dir| "-I#{dir}" })
|
277
|
+
arguments.push("-r#{spec.spec.name.gsub('-', File::SEPARATOR)}")
|
278
|
+
unless system(*arguments)
|
279
|
+
error "Command failed: #{show_command}"
|
280
|
+
abort
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
# vim: syntax=ruby
|