summaryrefslogtreecommitdiff
path: root/lib/net/imap
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/imap
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/imap')
-rw-r--r--lib/net/imap/net-imap.gemspec15
-rw-r--r--lib/net/imap/version.rb5
2 files changed, 9 insertions, 11 deletions
diff --git a/lib/net/imap/net-imap.gemspec b/lib/net/imap/net-imap.gemspec
index 696ec79ae7..2426e0932d 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 47d3de471f..0000000000
--- a/lib/net/imap/version.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-module Net
- module Imap
- VERSION = "0.1.0"
- end
-end