Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Hand duplicate of mime type array to MIME::Types.from_array #12

Closed
wants to merge 1 commit into from

3 participants

@rickenharp

Since from_array uses the array destructively, give it its own private
copy to do with it as it pleases.

This fixes #11

@rickenharp rickenharp Hand duplicate of mime type array to MIME::Types.from_array
Since from_array uses the array destructively, give it its own private
copy to do with it as it pleases.
82cbcac
@halostatue

Please tell me that you're the only project using MIME::Type.from_array. I'm deprecating it in mime-types 2.0 to kill it later. It isn't rich enough to use properly.

@copiousfreetime

@halostatue Looks like there are a few more that use it: https://github.com/search?l=ruby&q=+MIME%3A%3AType.from_array&ref=cmdform&search_target=global&type=Code

I'm happy to switch to whatever method you suggest for adding mime types. Would you prefer us to use MIME::Type.from_hash or MIME::Type.new() { }?

@halostatue

Yeah, I was seeing that as I was searching. I'm working on getting halostatue/mime-type#41 integrated which puts a lot more emphasis on the richness of the data as part of the 2.0 release I'm prepping.

I found this repo because it's marked as depending on mime-types—you have the dependency right with ~> (there's a lot of people who do it with >= 0 :-1:).

A couple of things that I'll point out looking at lib/heel/mime_map:

  • line 42 indicates images/svg; it should be image/svg. This already exists and has extensions svg and svgz.
  • line 43 indicates video/x-flv, which already exists with the extension flv.
  • line 44 indicates application/x-shockwave-flash, which already exists with extensions swf.
  • line 45 indicates 'text/plain' and adds some new types. These are new—I can easily see adding md, markdown, textile, rst, rdoc, etc. to text/plain (and I'll probably do so before the 2.0 release is finished).

As far as needing to create new types is concerned:

MIME::Type.new(content_type) { |t| t.extensions = extensions }

would be canonical, but with 2.0 you will also be able to do:

MIME::Type.new('content-type' => 'text/plainer', 'extensions' => %w(rb rhtml md markdown))

This is because the default registry data format is now JSON and I serialize to a hash and initialize from the JSON hash. I also support YAML initialization:

---
- ! ruby/object:MIME::Type:
  content-type: text/plainer
  extensions:
  - rb
  - rhtml
  - md
  - markdown

I'm deprecating MIME::Type.from_array because it isn't rich enough (too much inferred data, and only present because I had a slightly-braindead regexp-based parser) and MIME::Type.from_hash because I don't want to support that hash format anymore (many of the same reasons). Only MIME::Type#to_hash supports the format supported by MIME::Type.from_hash, whereas MIME::Type.new supports the output of MIME::Type#to_h.

@copiousfreetime

Sounds good, I'll update to use MIME::Type.new and remove the redundant entries. I've quite possibly had those redundant ones.

@halostatue

With respect to the other, halostatue/mime-types#43 covers what you pointed out. If you have a suggestion for a quick case that matches your use-case and the search you pointed out, I think I can add that (maybe a case where MIME::Types.new(content_type, extensions = nil) does what you expect).

@halostatue

You've also suggested, without realizing it, halostatue/mime-types#44. Any other APIs you want?

@copiousfreetime

@halostatue Nope, that's all I use right now, adding new mime types and extensions to existing ones. Thanks for your work :metal:

@copiousfreetime

Version 3.1.2 of heel released.

@jsonn jsonn referenced this pull request from a commit in jsonn/pkgsrc
taca Update heel 3.1.3.
## Version 3.1.3 - 2013-11-26
* URL encode the links to files [#14](copiousfreetime/heel#14)
* Fix pid file cleanup on ruby 2.0 [#15](copiousfreetime/heel#15)

## Version 3.1.2 - 2013-10-16
* Fix usage of Mime::Types [#12](copiousfreetime/heel#12) [#13](copiousfreetime/heel#13)

## Version 3.1.1 - 2013-09-29
* Fix request logging [#10](copiousfreetime/heel#10)
2d9bf19
@jsonn jsonn referenced this pull request from a commit in jsonn/pkgsrc
taca Update heel 3.1.3.
## Version 3.1.3 - 2013-11-26
* URL encode the links to files [#14](copiousfreetime/heel#14)
* Fix pid file cleanup on ruby 2.0 [#15](copiousfreetime/heel#15)

## Version 3.1.2 - 2013-10-16
* Fix usage of Mime::Types [#12](copiousfreetime/heel#12) [#13](copiousfreetime/heel#13)

## Version 3.1.1 - 2013-09-29
* Fix request logging [#10](copiousfreetime/heel#10)
d9933eb
@jsonn jsonn referenced this pull request from a commit in jsonn/pkgsrc
taca Update heel 3.1.3.
## Version 3.1.3 - 2013-11-26
* URL encode the links to files [#14](copiousfreetime/heel#14)
* Fix pid file cleanup on ruby 2.0 [#15](copiousfreetime/heel#15)

## Version 3.1.2 - 2013-10-16
* Fix usage of Mime::Types [#12](copiousfreetime/heel#12) [#13](copiousfreetime/heel#13)

## Version 3.1.1 - 2013-09-29
* Fix request logging [#10](copiousfreetime/heel#10)
f9a3caf
@notxarb notxarb referenced this pull request from a commit in pagodabox/nanobox-pkgsrc-lite
@notxarb notxarb