summaryrefslogtreecommitdiff
path: root/lib/net
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-07-29 00:31:52 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-07-30 19:03:18 +0900
commitb2d96abb42abbe2e01f010ffc9ac51f0f9a50002 (patch)
tree57791da8a71280c335109916376e13f5e0c63af3 /lib/net
parentcfbae7dae052180e5dde05a27948ae8d779eccab (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/net')
-rw-r--r--lib/net/ftp/net-ftp.gemspec9
-rw-r--r--lib/net/http.rb1
-rw-r--r--lib/net/http/net-http.gemspec15
-rw-r--r--lib/net/http/version.rb5
-rw-r--r--lib/net/imap.rb2
-rw-r--r--lib/net/imap/net-imap.gemspec15
-rw-r--r--lib/net/imap/version.rb5
-rw-r--r--lib/net/pop.rb5
-rw-r--r--lib/net/pop/net-pop.gemspec15
-rw-r--r--lib/net/pop/version.rb6
-rw-r--r--lib/net/protocol.rb2
-rw-r--r--lib/net/protocol/net-protocol.gemspec15
-rw-r--r--lib/net/protocol/version.rb5
-rw-r--r--lib/net/smtp.rb1
-rw-r--r--lib/net/smtp/net-smtp.gemspec15
-rw-r--r--lib/net/smtp/version.rb6
16 files changed, 58 insertions, 64 deletions
diff --git a/lib/net/ftp/net-ftp.gemspec b/lib/net/ftp/net-ftp.gemspec
index 6031ce7ccf9..893305cfb8b 100644
--- a/lib/net/ftp/net-ftp.gemspec
+++ b/lib/net/ftp/net-ftp.gemspec
@@ -1,13 +1,14 @@
+# frozen_string_literal: true
+
name = File.basename(__FILE__, ".gemspec")
-version = nil
-["lib", "../.."].find do |dir|
- version = File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
+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 = "net-ftp"
+ spec.name = name
spec.version = version
spec.authors = ["Shugo Maeda"]
spec.email = ["shugo@ruby-lang.org"]
diff --git a/lib/net/http.rb b/lib/net/http.rb
index fe237dcf665..fe856ac877b 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -388,6 +388,7 @@ module Net #:nodoc:
class HTTP < Protocol
# :stopdoc:
+ VERSION = "0.1.0"
Revision = %q$Revision$.split[1]
HTTPVersion = '1.1'
begin
diff --git a/lib/net/http/net-http.gemspec b/lib/net/http/net-http.gemspec
index cf3c5bd6a48..c6952c3c1bc 100644
--- a/lib/net/http/net-http.gemspec
+++ b/lib/net/http/net-http.gemspec
@@ -1,12 +1,15 @@
-begin
- require_relative "lib/net/http/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 = "net-http"
- spec.version = Net::Http::VERSION
+ spec.name = name
+ spec.version = version
spec.authors = ["NARUSE, Yui"]
spec.email = ["naruse@airemix.jp"]
diff --git a/lib/net/http/version.rb b/lib/net/http/version.rb
deleted file mode 100644
index 832d5971116..00000000000
--- a/lib/net/http/version.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-module Net
- module Http
- VERSION = "0.1.0"
- end
-end
diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index 704fdef382a..de13d0807c9 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -201,6 +201,8 @@ module Net
# Unicode", RFC 2152, May 1997.
#
class IMAP < Protocol
+ VERSION = "0.1.0"
+
include MonitorMixin
if defined?(OpenSSL::SSL)
include OpenSSL
diff --git a/lib/net/imap/net-imap.gemspec b/lib/net/imap/net-imap.gemspec
index 696ec79ae72..2426e0932df 100644
--- a/lib/net/imap/net-imap.gemspec
+++ b/lib/net/imap/net-imap.gemspec
@@ -1,12 +1,15 @@
-begin
- require_relative 'lib/net/imap/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 = "net-imap"
- spec.version = Net::Imap::VERSION
+ spec.name = name
+ spec.version = version
spec.authors = ["Shugo Maeda"]
spec.email = ["shugo@ruby-lang.org"]
diff --git a/lib/net/imap/version.rb b/lib/net/imap/version.rb
deleted file mode 100644
index 47d3de471ff..00000000000
--- a/lib/net/imap/version.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-module Net
- module Imap
- VERSION = "0.1.0"
- end
-end
diff --git a/lib/net/pop.rb b/lib/net/pop.rb
index 30161105f92..ed1963975b8 100644
--- a/lib/net/pop.rb
+++ b/lib/net/pop.rb
@@ -194,9 +194,8 @@ module Net
# String. Normally the unique-id is a hash of the message.
#
class POP3 < Protocol
-
- # svn revision of this library
- Revision = %q$Revision$.split[1]
+ # version of this library
+ VERSION = "0.1.0"
#
# Class Parameters
diff --git a/lib/net/pop/net-pop.gemspec b/lib/net/pop/net-pop.gemspec
index c1b0ffbd2b4..90d594f14aa 100644
--- a/lib/net/pop/net-pop.gemspec
+++ b/lib/net/pop/net-pop.gemspec
@@ -1,12 +1,15 @@
-begin
- require_relative "lib/net/pop/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 = "net-pop"
- spec.version = Net::POP3::VERSION
+ spec.name = name
+ spec.version = version
spec.authors = ["Yukihiro Matsumoto"]
spec.email = ["matz@ruby-lang.org"]
diff --git a/lib/net/pop/version.rb b/lib/net/pop/version.rb
deleted file mode 100644
index ef5c295cc3e..00000000000
--- a/lib/net/pop/version.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Net
- class Protocol; end
- class POP3 < Protocol
- VERSION = "0.1.0"
- end
-end
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index 07fbc6a21ff..cba92613c70 100644
--- a/lib/net/protocol.rb
+++ b/lib/net/protocol.rb
@@ -26,6 +26,8 @@ require 'io/wait'
module Net # :nodoc:
class Protocol #:nodoc: internal use only
+ VERSION = "0.1.0"
+
private
def Protocol.protocol_param(name, val)
module_eval(<<-End, __FILE__, __LINE__ + 1)
diff --git a/lib/net/protocol/net-protocol.gemspec b/lib/net/protocol/net-protocol.gemspec
index 2bfd2e29dde..a277c301d53 100644
--- a/lib/net/protocol/net-protocol.gemspec
+++ b/lib/net/protocol/net-protocol.gemspec
@@ -1,12 +1,15 @@
-begin
- require_relative "lib/net/protocol/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 = "net-protocol"
- spec.version = Net::Protocol::VERSION
+ spec.name = name
+ spec.version = version
spec.authors = ["Yukihiro Matsumoto"]
spec.email = ["matz@ruby-lang.org"]
diff --git a/lib/net/protocol/version.rb b/lib/net/protocol/version.rb
deleted file mode 100644
index ec51a4c4ef9..00000000000
--- a/lib/net/protocol/version.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-module Net
- class Protocol
- VERSION = "0.1.0"
- end
-end
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index 801f662d01c..f8121cd44f9 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -168,6 +168,7 @@ module Net
# 'Your Account', 'Your Password', :cram_md5)
#
class SMTP < Protocol
+ VERSION = "0.1.0"
Revision = %q$Revision$.split[1]
diff --git a/lib/net/smtp/net-smtp.gemspec b/lib/net/smtp/net-smtp.gemspec
index f0aae585de1..4c8c07810bd 100644
--- a/lib/net/smtp/net-smtp.gemspec
+++ b/lib/net/smtp/net-smtp.gemspec
@@ -1,12 +1,15 @@
-begin
- require_relative "lib/net/smtp/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 = "net-smtp"
- spec.version = Net::SMTP::VERSION
+ spec.name = name
+ spec.version = version
spec.authors = ["Yukihiro Matsumoto"]
spec.email = ["matz@ruby-lang.org"]
diff --git a/lib/net/smtp/version.rb b/lib/net/smtp/version.rb
deleted file mode 100644
index 7f5aaaa6db9..00000000000
--- a/lib/net/smtp/version.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Net
- class Protocol; end
- class SMTP < Protocol
- VERSION = "0.1.0"
- end
-end