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

Shim of the mime-types gem #6

Closed
Fryguy opened this issue Jun 26, 2017 · 11 comments
Closed

Shim of the mime-types gem #6

Fryguy opened this issue Jun 26, 2017 · 11 comments

Comments

@Fryguy
Copy link
Contributor

Fryguy commented Jun 26, 2017

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

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 rest-client/rest-client#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
Copy link
Contributor Author

Fryguy commented Jun 26, 2017

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

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
Copy link
Contributor Author

Fryguy commented Jun 28, 2017

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

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

@Fryguy
Copy link
Contributor Author

Fryguy commented Jun 28, 2017

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

Absolutely @Fryguy that would be awesome!

@ioquatix
Copy link

ioquatix commented Sep 6, 2017

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: rubygems/rubygems#1746

@Fryguy
Copy link
Contributor Author

Fryguy commented Sep 7, 2017

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


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

NickLaMuro commented Sep 7, 2017

...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): rubygems/bundler#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
Copy link

ioquatix commented Sep 7, 2017

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

Fryguy commented Jan 21, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants