-
Notifications
You must be signed in to change notification settings - Fork 17
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
Issue with gem loading with rails/zeitwerk on linux #24
Comments
I'm also seeing this issue. Ruby 2.7.2 |
Hey guys, thanks for the report. This gem was named a while ago and it seems it didn't follow the recommendation made at https://guides.rubygems.org/name-your-gem/:
So I'll recommend importing manually using lowercase, always, and apologize for the mistake made here in the first place. For the specific case mentioned by @cecilian, we'll have to think of something else, because it seems the "zeitwerk" tool can't auto-discover the gem (is that right?). Renaming the gem itself at this point seems improbable but not off the table. You can possibly file an issue with zeitwerk to support this case somehow, if that's even technically possible. I'll come back to you when we conclude on what to do specifically. I'm personally leaning on renaming the gem to match rubygem's recommendations. |
Looked into seeing what we can do here, and there's a roadblock: rubygems doesn't allow uploading So we'd be forced to have a new gem named So for your fix @cecilian, I think you'll have to stick to the manual import in For @TheJohnzo, as the rubygems docs mention, you should always just import with lowercase letters, regardless of what the gem name actually is on rubygems. Unless there are any objections, I'll close this issue soon. |
Hello @UmanShahzad , thank you for looking into this. So zeitwerk is the default code loader for Rails 6 upwards. Since the gem loading was working prior to its introduction, I think it is the case that the loading process was made stricter in zeitwerk. For this reason I think it's unlikely the rails/zeitwerk maintainers will be inclined to make an allowance in this case, also because the gem naming didn't follow conventions in the first place. I can live with my manual require, it's not a problem, but for the reason stated above (loading with Zeitwerk will be the default for rails going forward) I would recommend that you address the issue (my guess is a breaking change is necessary, but after all we have semver for that). I didn't investigate it but it's possible that the problem is not the gem name itself but rather the naming of the module. In any case no problem for me about closing this issue. |
@cecilian I looked more into Rails6 Zeitwerk specifically and it's likely a module-name issue and not a gem name issue: https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#customizing-inflections Zeitwerk expects the imported constants to be a camellized version of the file name, so e.g. irb(main):001:0> "ipinfo".camelize()
=> "Ipinfo" After adding this to ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'IPinfo'
end The camelize function works for IPinfo: irb(main):001:0> "ipinfo".camelize
=> "IPinfo" I'm not 100% certain this will fix your issue, but your fix is certainly much simpler than whatever else we'd have to do. |
My quick workaround if RUBY_PLATFORM =~ /linux/
require 'ipinfo'
else
require 'IPinfo'
end |
Hey there, I just wanted to let you know that I tried adding the inflection as you suggested but it doesn't work, i.e. the gem is still working fine on OSX but not working on linux. The only thing that's making it work is the optional manual require (mine or the one suggested by @juliandicks ). If you don't intend to look into an official fix I think it would be better to add a line to the Readme detailing what has to be done to have the gem working under linux with Rails >=6 |
Hello,
the fact that the gem name contains two uppercase characters makes it unavailable under case-sensitive OSs like linux because autoloading with zeitwerk doesn't manage to pick it up.
Manual require fails too:
but it works using the file name in lowercase:
In my case all was working in my development environment (OSX) but failed on circleCI.
At the moment the only workaround I've found is adding the following line to
application.rb
:Would it be possible to address this issue so that the gem can be required automatically also under linux?
Thank you
gem version: 1.0.1
rails version: 6.0.3.2
The text was updated successfully, but these errors were encountered: