discourse / mini_mime

minimal mime type library
MIT License
95 stars 34 forks source link

Shim of the mime-types gem #6

Closed Fryguy closed 5 months ago

Fryguy commented 7 years ago

In ManageIQ, we've found a way to "stub" out any mime-types gem references, and redirect through to mini_mime. This gives us the savings from mini_mime, even for gems that don't yet directly use it (in our case, rest-client, mail, and capybara). The PR that does this is in our app is here: https://github.com/ManageIQ/manageiq/pull/14525/files . Essentially what we've done is create a "fake" mime-types gem, then in our Gemfile point to the fake .gemspec file. The "fake" mime-types gem is basically a thin wrapper around mini_mime with the interface of mime_types.

Is this something you'd be interested in for the mini_mime gem? I know we can't actually publish the fake mime-types gem, but my thought is that it's possible to put the .gemspec and the fake class in mini_mime, and then give instructions in the README on how a user might go about changing their Gemfile to point to the .gemspec file provided. Something roughly like:


├── lib
│   ├── mime-types-redirector
│   │   ├── lib
│   │   │   ├── mime
│   │   │   │   └── types.rb
│   │   │   └── mime-types.rb
│   │   └── mime-types.gemspec
│   ├── mini_mime
│   │   └── version.rb
│   └── mini_mime.rb

README

If you would like all references to mime-types to instead be redirected though mini_mime, include the following in your Gemfile:

gem "mini_mime"
gem "mime-types", :path => File.expand_path("lib/mime-types-redirector", Gem::Specification.find_by_name("mini_mime").gem_dir)
SamSaffron commented 7 years ago

I am totally comfortable documentation for this in the readme 👍 but feel like the "ninja" redirection belongs in a "ninja" redirection gem.

Also we got to apply pressure on rest-client and capybara, mail have already accepted the change. Strongly recommend getting actual PRs going for capybara and rest-client to move this along.

At the moment https://github.com/rest-client/rest-client/pull/557 needs some love to get it working again, but it did sit in the queue forever, not sure what the state is for capybara? and updates about it?

Fryguy commented 7 years ago

but feel like the "ninja" redirection belongs in a "ninja" redirection gem.

I agree, but the problem is, I don't think it can be done. The reason is, some random gem's gemspec will have mime-types in it literally. You can't get around this unless the "ninja" gem is also named "mime-types", and if it has the same name we can't push it to rubygems.org. Unless you are suggesting we have a gem named mime-types-redirector, and it internally has the mime-types.gemspec as described above?

SamSaffron commented 7 years ago

I follow, I just mean put all the hacks into one gem (that is not this gem) that way as time passes by and people fix stuff we don't need to carry around and maintain the redirector code.

Fryguy commented 7 years ago

not sure what the state is for capybara? and updates about it?

just opened the PR on capybara: https://github.com/teamcapybara/capybara/pull/1884

Fryguy commented 7 years ago

not sure what the state is for capybara? and updates about it?

just opened the PR on capybara: teamcapybara/capybara#1884

And it's merged. @SamSaffron, do you want help rebasing rest-client/rest-client#557 ?

SamSaffron commented 7 years ago

Absolutely @Fryguy that would be awesome!

ioquatix commented 6 years ago

This is a good idea but the problem really lies with how Gemfiles works.

It would be far superiour to be able to alias gems so that you could force a specific name to redirect to another gem transparently.

This is discussed here: https://github.com/rubygems/rubygems/issues/1746

Fryguy commented 6 years ago

Oh thanks for the bump...I totally forgot I offered to update the rest-client PR :joy:


So the "hack" didn't work 100%, though I can't remember the edge case issue, and that's why we haven't moved forward on making it a real gem...not to mention that it got lower priority than other things we've been working on. @NickLaMuro, do you remember the details on what the issue was with our shim?

NickLaMuro commented 6 years ago

...do you remember the details on what the issue was with our shim?

Part of it was actually a bundler issue that I ended up correcting (in as part of bundler v1.15.2): https://github.com/bundler/bundler/pull/5817

Which was particular to our setup with multiple git branch based plugins and those plugins in turn symlinking/sourcing the main repo in the plugin repos when working on them in development. I think we got that ironed out at this point, and I am not sure of any other issues that have come about because of it.

Might have been something else, but I forget.

It would be far superiour to be able to alias gems so that you could force a specific name to redirect to another gem transparently.

@ioquatix Indeed, but has the problem of also requiring another feature be added to rubygems just for that solution to work. Not saying it isn't more elegant, but requires more hoops to jump through for that to come to fruition.

Been a bit since I worked on this, but I also think the API from mini-mime to mime-types isn't 1-to-1, so this proxy gem would probably still be necessary, and this would just be another piece to the puzzle in the middle.

ioquatix commented 6 years ago

@ioquatix Indeed, but has the problem of also requiring another feature be added to rubygems just for that solution to work. Not saying it isn't more elegant, but requires more hoops to jump through for that to come to fruition.

I understand where you are coming from. It's just my style of software engineering to solve the core problems elegantly rather than hacks, because over time accumulation of elegant solutions is far preferable to accumulation of hacks. IMHO :)

Fryguy commented 3 years ago

FWIW, we've moved the code into a dedicated repo, if anyone is interested. In our app, we've built this as a replacement mime-types gem and host it on our custom gem server. https://github.com/ManageIQ/mime-types-redirector