fastruby / dotenv_validator

This gem check if required env variables are present and its format using the .env and .env.sample files from Dotenv.
https://www.fastruby.io/blog/open-source/introducing-dotenv-validator.html
MIT License
50 stars 4 forks source link

Namespace the version file on the file system #30

Closed JoshCheek closed 3 years ago

JoshCheek commented 3 years ago

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.

Here is a demonstration that requiring "version" winds up requiring this file:

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

Additionally, I built the gem to verify that this works as expected, and then saw that the built gem wound up in a pkg directory, which git was aware of. This seemed precarious b/c it would be easy enough to add and commit previous gems into the repo. So I also added pkg to .gitignore.

I will abide by the code of conduct.