Skip to content

Commit 4e561c1

Browse files
nobuhsbt
authored andcommitted
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.
1 parent a8ac8a0 commit 4e561c1

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

lib/weakref.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#
1818

1919
class WeakRef < Delegator
20+
VERSION = "0.1.0"
2021

2122
##
2223
# RefError is raised when a referenced object has been recycled by the

lib/weakref/version.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.

weakref.gemspec

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
lib = File.expand_path("lib", __dir__)
2-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3-
require "weakref/version"
1+
# frozen_string_literal: true
2+
3+
name = File.basename(__FILE__, ".gemspec")
4+
version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir|
5+
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
6+
/^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
7+
end rescue nil
8+
end
49

510
Gem::Specification.new do |spec|
6-
spec.name = "weakref"
7-
spec.version = Weakref::VERSION
11+
spec.name = name
12+
spec.version = version
813
spec.authors = ["Yukihiro Matsumoto"]
914
spec.email = ["matz@ruby-lang.org"]
1015

0 commit comments

Comments
 (0)