Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed

Conversation

rickenharp
Copy link

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

This fixes #11

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

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
Copy link
Owner

@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
Copy link

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 👎).

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
Copy link
Owner

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

@halostatue
Copy link

With respect to the other, mime-types/ruby-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
Copy link

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

@copiousfreetime
Copy link
Owner

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

@copiousfreetime
Copy link
Owner

Version 3.1.2 of heel released.

jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Mar 15, 2014
## 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)
jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Mar 17, 2014
## 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)
jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Oct 11, 2014
## 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Opening a file from heel throws an exception
3 participants