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

How can I check loaded version of XDG module? #4

Closed
depesz opened this issue Jan 26, 2022 · 5 comments
Closed

How can I check loaded version of XDG module? #4

depesz opened this issue Jan 26, 2022 · 5 comments

Comments

@depesz
Copy link

depesz commented Jan 26, 2022

Overview

I have varying version of xdg loaded in many places - in one it's 2.2.5, in another it's 4.5.0. All depending on ruby version, I guess.

The problem is that they have very different APIs.

I can work around it, by adding version check, but I'd need to know how to find version of used XDG library.

Or, perhaps, how else should I know whether I can use, very convenient XDG['CONFIG'].find(), and where I have to iterate over XDG::Config.new.directories and check for file existence...

@bkuhlmann
Copy link
Owner

bkuhlmann commented Jan 26, 2022

Hey, Hubert, nice to meet you. 👋 I've been subscribed to your PostgreSQL articles for some time.

If you are asking how to quickly determine which version of XDG supports which version of Ruby, that can be done several ways:

  • Versions - All version details are listed here. To match up which Ruby version XDG was upgraded to, you'd only need to search for the Updated to Ruby string to find what you need.
  • RubyGems - Same as above but you can click on each version to immediately see which version of Ruby is required.
  • XDG::Identity - With XDG 3.0.0, the Identity module was introduced which had a constant that you could query for version information. Example: XDG::Identity::VERSION. As of XDG 6.1.0, though, that module has been removed in favor of using the xdg.gemspec only. Regardless, all versions from 3.0.0 to 6.1.0 use XDG::Config.new. Those prior to 3.0.0 use XDG["CONFIG"].

Does that help?

@depesz
Copy link
Author

depesz commented Jan 26, 2022

Hmnmm .. I have 2.2.5, and when I tried XDG::Config.new:

[1] pry(main)> require 'xdg'
=> true

[2] pry(main)> XDG::Identity::VERSION
NameError: uninitialized constant XDG::Identity
from (pry):2:in `__pry__'

[3] pry(main)> XDG::Config.new
NameError: uninitialized constant XDG::Config
Did you mean?  RbConfig
from (pry):3:in `__pry__'

[4] pry(main)> XDG["CONFIG"]
=> #<XDG::BaseDir:0x00005610baaae0d0 @environment_variables=["XDG_CONFIG_HOME", "XDG_CONFIG_DIRS"]>

[5] pry(main)> Gem.loaded_specs["xdg"].version
=> Gem::Version.new("2.2.5")

So it looks that with 2.2.5 I don't have XDG::Config, and I don't have XDG::Identity :(

@depesz
Copy link
Author

depesz commented Jan 26, 2022

As a side note:

[10] pry(main)> XDG::VERSION
=> "2.2.3"

No idea what that means.

@bkuhlmann
Copy link
Owner

bkuhlmann commented Jan 26, 2022

Ah, apologies. I see the problem now. I miss quoted you earlier. You must be on 3.0.0 or higher to leverage XDG::Identity::VERSION or even XDG::Config. I've updated my notes above so they make more sense. Anything prior to 3.0.0 is before my time of taking ownership of this gem and that code base was difficult to deal with which is why the Object API changed to be more manageable but also more testable.

In your case, I think you'd have everything you need by doing something close to the following:

defined?(XDG::Config) ? "Using 3.0.0 or higher" : "Using 2.2.5 or lower"

That should allow you to feature toggle your code as desired.

@depesz
Copy link
Author

depesz commented Jan 27, 2022

That works. Thanks a lot.

@depesz depesz closed this as completed Jan 27, 2022
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

No branches or pull requests

2 participants