Skip to content

Commit c154a12

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 826dcff commit c154a12

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

lib/net/http.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ class HTTPHeaderSyntaxError < StandardError; end
388388
class HTTP < Protocol
389389

390390
# :stopdoc:
391+
VERSION = "0.1.0"
391392
Revision = %q$Revision$.split[1]
392393
HTTPVersion = '1.1'
393394
begin

lib/net/http/version.rb

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

net-http.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/net/http/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 = "net-http"
9-
spec.version = Net::Http::VERSION
11+
spec.name = name
12+
spec.version = version
1013
spec.authors = ["NARUSE, Yui"]
1114
spec.email = ["naruse@airemix.jp"]
1215

0 commit comments

Comments
 (0)