Skip to content

Commit 160f51b

Browse files
committed
πŸ§‘β€πŸ’» Improved loading of version.rb
- split on Ruby 3.1+
1 parent a7f07e6 commit 160f51b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

β€Žversion_gem.gemspec

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# frozen_string_literal: true
22

3+
gem_version =
4+
if RUBY_VERSION >= "3.1"
5+
# Loading version into an anonymous module allows version.rb to get code coverage from SimpleCov!
6+
# See: https://github.com/simplecov-ruby/simplecov/issues/557#issuecomment-2630782358
7+
Module.new.tap { |mod| Kernel.load("lib/version_gem/version.rb", mod) }::VersionGem::Version::VERSION
8+
else
9+
# TODO: Remove this hack once support for Ruby 3.0 and below is removed
10+
Kernel.load("lib/version_gem/version.rb")
11+
g_ver = VersionGem::Version::VERSION
12+
VersionGem::Version.send(:remove_const, :VERSION)
13+
g_ver
14+
end
15+
316
Gem::Specification.new do |spec|
417
# Linux distros may package ruby gems differently,
518
# and securely certify them independently via alternate package management systems.
@@ -18,9 +31,7 @@ Gem::Specification.new do |spec|
1831
end
1932

2033
spec.name = "version_gem"
21-
# Loading version into an anonymous module allows version.rb to get code coverage from SimpleCov!
22-
# See: https://github.com/simplecov-ruby/simplecov/issues/557#issuecomment-2630782358
23-
spec.version = Module.new.tap { |mod| Kernel.load("lib/version_gem/version.rb", mod) }::VersionGem::Version::VERSION
34+
spec.version = gem_version
2435
spec.authors = ["Peter Boling"]
2536
2637

0 commit comments

Comments
Β (0)