Namespace the version file on the file system#30
Merged
etagwerker merged 2 commits intofastruby:mainfrom Sep 10, 2021
Merged
Conversation
The version file is at the toplevel dir in `lib`, which makes it not namespaced on the file system. Thus `require "version"` is really requiring `dotenv_validator`'s version, despite the fact that this is unexpected. The solution that people have arrived at is to namespace files within a directory that matches the gem name. So, this movew `lib/version.rb` to `lib/dotenv_validator/version.rb`. For a bit more context on this, I go into it [here](https://github.com/JoshCheek/elective-building-a-gem/blob/085283ee848287f2b57f8ec5da963c5d775eb3de/Day2.md#namespacing-our-gems-files-and-classes). ```sh gem install --no-document dotenv_validator -v 1.0.0 >/dev/null && ruby -e ' features = $LOADED_FEATURES.dup require "version" puts $LOADED_FEATURES - features' /Users/josh/.rubies/ruby-3.0.2/lib/ruby/3.0.0/rubygems/bundler_version_finder.rb /Users/josh/.gem/ruby/3.0.2/gems/dotenv_validator-1.0.0/lib/version.rb ```
etagwerker
approved these changes
Sep 10, 2021
Member
etagwerker
left a comment
There was a problem hiding this comment.
@JoshCheek Looks good, thanks! 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The version file is at the toplevel dir in
lib, which makes it not namespaced on the file system. Thusrequire "version"is really requiringdotenv_validator's version, despite the fact that this is unexpected. The solution that people have arrived at is to namespace files within a directory that matches the gem name. So, this movewlib/version.rbtolib/dotenv_validator/version.rb.For a bit more context on this, I go into it here.
Here is a demonstration that requiring "version" winds up requiring this file:
Additionally, I built the gem to verify that this works as expected, and then saw that the built gem wound up in a
pkgdirectory, whichgitwas aware of. This seemed precarious b/c it would be easy enough to add and commit previous gems into the repo. So I also addedpkgto.gitignore.I will abide by the code of conduct.