diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-29 00:31:52 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-30 19:03:18 +0900 |
commit | b2d96abb42abbe2e01f010ffc9ac51f0f9a50002 (patch) | |
tree | 57791da8a71280c335109916376e13f5e0c63af3 /lib/timeout | |
parent | cfbae7dae052180e5dde05a27948ae8d779eccab (diff) | |
download | ruby-b2d96abb42abbe2e01f010ffc9ac51f0f9a50002.tar.gz |
Extract version number from the source
"requiring version.rb" strategy has some issues.
- cannot work when cross-compiling
- often introduces wrong namespace
- must know the superclasses
- costs at each runtime than at build-time
etc.
Diffstat (limited to 'lib/timeout')
-rw-r--r-- | lib/timeout/timeout.gemspec | 15 | ||||
-rw-r--r-- | lib/timeout/version.rb | 3 |
2 files changed, 9 insertions, 9 deletions
diff --git a/lib/timeout/timeout.gemspec b/lib/timeout/timeout.gemspec index 7b650bdc31..12ac062b6d 100644 --- a/lib/timeout/timeout.gemspec +++ b/lib/timeout/timeout.gemspec @@ -1,12 +1,15 @@ -begin - require_relative "lib/timeout/version" -rescue LoadError # Fallback to load version file in ruby core repository - require_relative "version" +# frozen_string_literal: true + +name = File.basename(__FILE__, ".gemspec") +version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir| + break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line| + /^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1 + end rescue nil end Gem::Specification.new do |spec| - spec.name = "timeout" - spec.version = Timeout::VERSION + spec.name = name + spec.version = version spec.authors = ["Yukihiro Matsumoto"] spec.email = ["matz@ruby-lang.org"] diff --git a/lib/timeout/version.rb b/lib/timeout/version.rb deleted file mode 100644 index 39fc6eec5f..0000000000 --- a/lib/timeout/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Timeout - VERSION = "0.1.0" -end |