diff options
author | Nobuyoshi Nakada <[email protected]> | 2020-07-29 00:31:52 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2020-07-30 19:03:18 +0900 |
commit | b2d96abb42abbe2e01f010ffc9ac51f0f9a50002 (patch) | |
tree | 57791da8a71280c335109916376e13f5e0c63af3 /lib/weakref | |
parent | cfbae7dae052180e5dde05a27948ae8d779eccab (diff) |
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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3375
Diffstat (limited to 'lib/weakref')
-rw-r--r-- | lib/weakref/version.rb | 3 | ||||
-rw-r--r-- | lib/weakref/weakref.gemspec | 15 |
2 files changed, 10 insertions, 8 deletions
diff --git a/lib/weakref/version.rb b/lib/weakref/version.rb deleted file mode 100644 index 893da80753..0000000000 --- a/lib/weakref/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Weakref - VERSION = "0.1.0" -end diff --git a/lib/weakref/weakref.gemspec b/lib/weakref/weakref.gemspec index 886ae13d9f..a7c83a53e7 100644 --- a/lib/weakref/weakref.gemspec +++ b/lib/weakref/weakref.gemspec @@ -1,10 +1,15 @@ -lib = File.expand_path("lib", __dir__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "weakref/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 = "weakref" - spec.version = Weakref::VERSION + spec.name = name + spec.version = version spec.authors = ["Yukihiro Matsumoto"] spec.email = ["[email protected]"] |