Skip to content

Commit b2d96ab

Browse files
committed
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 cfbae7d commit b2d96ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+190
-186
lines changed

lib/cgi.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@
288288
#
289289

290290
class CGI
291+
VERSION = "0.1.0"
291292
end
292293

293294
require 'cgi/core'

lib/cgi/cgi.gemspec

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
begin
2-
require_relative "lib/cgi/version"
3-
rescue LoadError # Fallback to load version file in ruby core repository
4-
require_relative "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
58
end
69

710
Gem::Specification.new do |spec|
8-
spec.name = "cgi"
9-
spec.version = CGI::VERSION
11+
spec.name = name
12+
spec.version = version
1013
spec.authors = ["Yukihiro Matsumoto"]
1114
spec.email = ["matz@ruby-lang.org"]
1215

lib/cgi/version.rb

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

lib/delegate.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
# Be advised, RDoc will not detect delegated methods.
4040
#
4141
class Delegator < BasicObject
42+
VERSION = "0.1.0"
43+
4244
kernel = ::Kernel.dup
4345
kernel.class_eval do
4446
alias __raise__ raise

lib/delegate/delegate.gemspec

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
begin
2-
require_relative "lib/delegate/version"
3-
rescue LoadError # Fallback to load version file in ruby core repository
4-
require_relative "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
58
end
69

710
Gem::Specification.new do |spec|
8-
spec.name = "delegate"
9-
spec.version = Delegator::VERSION
11+
spec.name = name
12+
spec.version = version
1013
spec.authors = ["Yukihiro Matsumoto"]
1114
spec.email = ["matz@ruby-lang.org"]
1215

lib/delegate/version.rb

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

lib/forwardable.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@
110110
#
111111
module Forwardable
112112
require 'forwardable/impl'
113-
require "forwardable/version"
113+
114+
# Version of +forwardable.rb+
115+
VERSION = "1.3.1"
116+
FORWARDABLE_VERSION = VERSION
114117

115118
@debug = nil
116119
class << self

lib/forwardable/forwardable.gemspec

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
begin
2-
require_relative "lib/forwardable/version"
3-
rescue LoadError
4-
# for Ruby core repository
5-
require_relative "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
68
end
79

810
Gem::Specification.new do |spec|
9-
spec.name = "forwardable"
10-
spec.version = Forwardable::VERSION
11+
spec.name = name
12+
spec.version = version
1113
spec.authors = ["Keiju ISHITSUKA"]
1214
spec.email = ["keiju@ruby-lang.org"]
1315

lib/forwardable/version.rb

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

lib/getoptlong.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585
# hello -n 6 --name -- /tmp
8686
#
8787
class GetoptLong
88+
# Version.
89+
VERSION = "0.1.0"
90+
8891
#
8992
# Orderings.
9093
#

0 commit comments

Comments
 (0)