From b2d96abb42abbe2e01f010ffc9ac51f0f9a50002 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 29 Jul 2020 00:31:52 +0900 Subject: 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. --- lib/cgi.rb | 1 + lib/cgi/cgi.gemspec | 15 +++++++++------ lib/cgi/version.rb | 3 --- lib/delegate.rb | 2 ++ lib/delegate/delegate.gemspec | 15 +++++++++------ lib/delegate/version.rb | 3 --- lib/forwardable.rb | 5 ++++- lib/forwardable/forwardable.gemspec | 16 +++++++++------- lib/forwardable/version.rb | 5 ----- lib/getoptlong.rb | 3 +++ lib/getoptlong/getoptlong.gemspec | 15 +++++++++------ lib/getoptlong/version.rb | 3 --- lib/net/ftp/net-ftp.gemspec | 9 +++++---- lib/net/http.rb | 1 + lib/net/http/net-http.gemspec | 15 +++++++++------ lib/net/http/version.rb | 5 ----- lib/net/imap.rb | 2 ++ lib/net/imap/net-imap.gemspec | 15 +++++++++------ lib/net/imap/version.rb | 5 ----- lib/net/pop.rb | 5 ++--- lib/net/pop/net-pop.gemspec | 15 +++++++++------ lib/net/pop/version.rb | 6 ------ lib/net/protocol.rb | 2 ++ lib/net/protocol/net-protocol.gemspec | 15 +++++++++------ lib/net/protocol/version.rb | 5 ----- lib/net/smtp.rb | 1 + lib/net/smtp/net-smtp.gemspec | 15 +++++++++------ lib/net/smtp/version.rb | 6 ------ lib/observer.rb | 1 + lib/observer/observer.gemspec | 15 +++++++++------ lib/observer/version.rb | 3 --- lib/open3.rb | 1 + lib/open3/open3.gemspec | 15 +++++++++------ lib/open3/version.rb | 3 --- lib/optparse/optparse.gemspec | 7 ++++--- lib/ostruct.rb | 3 +-- lib/ostruct/ostruct.gemspec | 14 +++++++------- lib/ostruct/version.rb | 5 ----- lib/pstore.rb | 2 ++ lib/pstore/pstore.gemspec | 15 +++++++++------ lib/pstore/version.rb | 3 --- lib/singleton.rb | 2 ++ lib/singleton/singleton.gemspec | 15 +++++++++------ lib/singleton/version.rb | 3 --- lib/timeout.rb | 2 ++ lib/timeout/timeout.gemspec | 15 +++++++++------ lib/timeout/version.rb | 3 --- lib/tracer.rb | 1 + lib/tracer/tracer.gemspec | 16 +++++++++------- lib/tracer/version.rb | 5 ----- lib/weakref.rb | 1 + lib/weakref/version.rb | 3 --- lib/weakref/weakref.gemspec | 15 ++++++++++----- 53 files changed, 190 insertions(+), 186 deletions(-) delete mode 100644 lib/cgi/version.rb delete mode 100644 lib/delegate/version.rb delete mode 100644 lib/forwardable/version.rb delete mode 100644 lib/getoptlong/version.rb delete mode 100644 lib/net/http/version.rb delete mode 100644 lib/net/imap/version.rb delete mode 100644 lib/net/pop/version.rb delete mode 100644 lib/net/protocol/version.rb delete mode 100644 lib/net/smtp/version.rb delete mode 100644 lib/observer/version.rb delete mode 100644 lib/open3/version.rb delete mode 100644 lib/ostruct/version.rb delete mode 100644 lib/pstore/version.rb delete mode 100644 lib/singleton/version.rb delete mode 100644 lib/timeout/version.rb delete mode 100644 lib/tracer/version.rb delete mode 100644 lib/weakref/version.rb diff --git a/lib/cgi.rb b/lib/cgi.rb index 4f16f309da..a125eef403 100644 --- a/lib/cgi.rb +++ b/lib/cgi.rb @@ -288,6 +288,7 @@ # class CGI + VERSION = "0.1.0" end require 'cgi/core' diff --git a/lib/cgi/cgi.gemspec b/lib/cgi/cgi.gemspec index 58bd77027d..57dd346db5 100644 --- a/lib/cgi/cgi.gemspec +++ b/lib/cgi/cgi.gemspec @@ -1,12 +1,15 @@ -begin - require_relative "lib/cgi/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 = "cgi" - spec.version = CGI::VERSION + spec.name = name + spec.version = version spec.authors = ["Yukihiro Matsumoto"] spec.email = ["matz@ruby-lang.org"] diff --git a/lib/cgi/version.rb b/lib/cgi/version.rb deleted file mode 100644 index 9d17c91b95..0000000000 --- a/lib/cgi/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -class CGI - VERSION = "0.1.0" -end diff --git a/lib/delegate.rb b/lib/delegate.rb index a1fded6425..cf8d39a982 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -39,6 +39,8 @@ # Be advised, RDoc will not detect delegated methods. # class Delegator < BasicObject + VERSION = "0.1.0" + kernel = ::Kernel.dup kernel.class_eval do alias __raise__ raise diff --git a/lib/delegate/delegate.gemspec b/lib/delegate/delegate.gemspec index 63b00c5894..bf7dd6600d 100644 --- a/lib/delegate/delegate.gemspec +++ b/lib/delegate/delegate.gemspec @@ -1,12 +1,15 @@ -begin - require_relative "lib/delegate/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 = "delegate" - spec.version = Delegator::VERSION + spec.name = name + spec.version = version spec.authors = ["Yukihiro Matsumoto"] spec.email = ["matz@ruby-lang.org"] diff --git a/lib/delegate/version.rb b/lib/delegate/version.rb deleted file mode 100644 index 1f0b4e0863..0000000000 --- a/lib/delegate/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Delegator < BasicObject - VERSION = "0.1.0" -end diff --git a/lib/forwardable.rb b/lib/forwardable.rb index 4cfade470a..d0f49f7309 100644 --- a/lib/forwardable.rb +++ b/lib/forwardable.rb @@ -110,7 +110,10 @@ # module Forwardable require 'forwardable/impl' - require "forwardable/version" + + # Version of +forwardable.rb+ + VERSION = "1.3.1" + FORWARDABLE_VERSION = VERSION @debug = nil class << self diff --git a/lib/forwardable/forwardable.gemspec b/lib/forwardable/forwardable.gemspec index 2a3e637e26..54e54f4c3c 100644 --- a/lib/forwardable/forwardable.gemspec +++ b/lib/forwardable/forwardable.gemspec @@ -1,13 +1,15 @@ -begin - require_relative "lib/forwardable/version" -rescue LoadError - # for 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 = "forwardable" - spec.version = Forwardable::VERSION + spec.name = name + spec.version = version spec.authors = ["Keiju ISHITSUKA"] spec.email = ["keiju@ruby-lang.org"] diff --git a/lib/forwardable/version.rb b/lib/forwardable/version.rb deleted file mode 100644 index 8f3e1f510e..0000000000 --- a/lib/forwardable/version.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Forwardable - # Version of +forwardable.rb+ - VERSION = "1.3.1" - FORWARDABLE_VERSION = VERSION -end diff --git a/lib/getoptlong.rb b/lib/getoptlong.rb index ff7674f1cb..6d4922ec9d 100644 --- a/lib/getoptlong.rb +++ b/lib/getoptlong.rb @@ -85,6 +85,9 @@ # hello -n 6 --name -- /tmp # class GetoptLong + # Version. + VERSION = "0.1.0" + # # Orderings. # diff --git a/lib/getoptlong/getoptlong.gemspec b/lib/getoptlong/getoptlong.gemspec index 5e218b8e93..123977c1f3 100644 --- a/lib/getoptlong/getoptlong.gemspec +++ b/lib/getoptlong/getoptlong.gemspec @@ -1,12 +1,15 @@ -begin - require_relative "lib/getoptlong/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 = "getoptlong" - spec.version = GetoptLong::VERSION + spec.name = name + spec.version = version spec.authors = ["Yukihiro Matsumoto"] spec.email = ["matz@ruby-lang.org"] diff --git a/lib/getoptlong/version.rb b/lib/getoptlong/version.rb deleted file mode 100644 index 6375fb8ad1..0000000000 --- a/lib/getoptlong/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -class GetoptLong - VERSION = "0.1.0" -end diff --git a/lib/net/ftp/net-ftp.gemspec b/lib/net/ftp/net-ftp.gemspec index 6031ce7ccf..893305cfb8 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 fe237dcf66..fe856ac877 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 cf3c5bd6a4..c6952c3c1b 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 832d597111..0000000000 --- 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 704fdef382..de13d0807c 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 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 diff --git a/lib/net/pop.rb b/lib/net/pop.rb index 30161105f9..ed1963975b 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 c1b0ffbd2b..90d594f14a 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 ef5c295cc3..0000000000 --- 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 07fbc6a21f..cba92613c7 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 2bfd2e29dd..a277c301d5 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 ec51a4c4ef..0000000000 --- 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 801f662d01..f8121cd44f 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 f0aae585de..4c8c07810b 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 7f5aaaa6db..0000000000 --- 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 diff --git a/lib/observer.rb b/lib/observer.rb index 0078d81449..f242cddc24 100644 --- a/lib/observer.rb +++ b/lib/observer.rb @@ -136,6 +136,7 @@ # ticker.add_observer(warner, :call) # ticker.run module Observable + VERSION = "0.1.0" # # Add +observer+ as an observer on this object. So that it will receive diff --git a/lib/observer/observer.gemspec b/lib/observer/observer.gemspec index 188c6bae76..f438f17437 100644 --- a/lib/observer/observer.gemspec +++ b/lib/observer/observer.gemspec @@ -1,12 +1,15 @@ -begin - require_relative "lib/observer/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 = "observer" - spec.version = Observer::VERSION + spec.name = name + spec.version = version spec.authors = ["Yukihiro Matsumoto"] spec.email = ["matz@ruby-lang.org"] diff --git a/lib/observer/version.rb b/lib/observer/version.rb deleted file mode 100644 index 92b5098774..0000000000 --- a/lib/observer/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Observer - VERSION = "0.1.0" -end diff --git a/lib/open3.rb b/lib/open3.rb index 3ee81c30ac..98213c9788 100644 --- a/lib/open3.rb +++ b/lib/open3.rb @@ -30,6 +30,7 @@ # module Open3 + VERSION = "0.1.0" # Open stdin, stdout, and stderr streams and start external executable. # In addition, a thread to wait for the started process is created. diff --git a/lib/open3/open3.gemspec b/lib/open3/open3.gemspec index 543416e427..b029c04ee8 100644 --- a/lib/open3/open3.gemspec +++ b/lib/open3/open3.gemspec @@ -1,12 +1,15 @@ -begin - require_relative "lib/open3/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 = "open3" - spec.version = Open3::VERSION + spec.name = name + spec.version = version spec.authors = ["Yukihiro Matsumoto"] spec.email = ["matz@ruby-lang.org"] diff --git a/lib/open3/version.rb b/lib/open3/version.rb deleted file mode 100644 index c670b79ebc..0000000000 --- a/lib/open3/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Open3 - VERSION = "0.1.0" -end diff --git a/lib/optparse/optparse.gemspec b/lib/optparse/optparse.gemspec index 25f81c08bb..3de0c07f43 100644 --- a/lib/optparse/optparse.gemspec +++ b/lib/optparse/optparse.gemspec @@ -1,7 +1,8 @@ +# frozen_string_literal: true + name = File.basename(__FILE__, ".gemspec") -version = nil -["lib", ".."].find do |dir| - version = File.foreach(File.join(__dir__, dir, "#{name}.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*OptionParser::Version\s*=\s*"(.*)"/ =~ line and break $1 end rescue nil end diff --git a/lib/ostruct.rb b/lib/ostruct.rb index a151fc0bed..e062fbdc9c 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -9,8 +9,6 @@ # See OpenStruct for an example. # -require_relative 'ostruct/version' - # # An OpenStruct is a data structure, similar to a Hash, that allows the # definition of arbitrary attributes with their accompanying values. This is @@ -75,6 +73,7 @@ require_relative 'ostruct/version' # of these properties compared to using a Hash or a Struct. # class OpenStruct + VERSION = "0.2.0" # # Creates a new OpenStruct object. By default, the resulting OpenStruct diff --git a/lib/ostruct/ostruct.gemspec b/lib/ostruct/ostruct.gemspec index 4f8507045e..a070e296c0 100644 --- a/lib/ostruct/ostruct.gemspec +++ b/lib/ostruct/ostruct.gemspec @@ -1,15 +1,15 @@ # frozen_string_literal: true -begin - require_relative "lib/ostruct/version" -rescue LoadError - # for Ruby core repository - require_relative "version" +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 = "ostruct" - spec.version = OpenStruct::VERSION + spec.name = name + spec.version = version spec.authors = ["Marc-Andre Lafortune"] spec.email = ["ruby-core@marc-andre.ca"] diff --git a/lib/ostruct/version.rb b/lib/ostruct/version.rb deleted file mode 100644 index 91a4044094..0000000000 --- a/lib/ostruct/version.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -class OpenStruct - VERSION = "0.2.0" -end diff --git a/lib/pstore.rb b/lib/pstore.rb index 1180fd50a0..f4e6e12c26 100644 --- a/lib/pstore.rb +++ b/lib/pstore.rb @@ -92,6 +92,8 @@ require "digest" # Needless to say, if you're storing valuable data with PStore, then you should # backup the PStore files from time to time. class PStore + VERSION = "0.1.0" + RDWR_ACCESS = {mode: IO::RDWR | IO::CREAT | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze RD_ACCESS = {mode: IO::RDONLY | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze WR_ACCESS = {mode: IO::WRONLY | IO::CREAT | IO::TRUNC | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze diff --git a/lib/pstore/pstore.gemspec b/lib/pstore/pstore.gemspec index e781c77043..d04fddcb0a 100644 --- a/lib/pstore/pstore.gemspec +++ b/lib/pstore/pstore.gemspec @@ -1,12 +1,15 @@ -begin - require_relative "lib/pstore/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 = "pstore" - spec.version = PStore::VERSION + spec.name = name + spec.version = version spec.authors = ["Yukihiro Matsumoto"] spec.email = ["matz@ruby-lang.org"] diff --git a/lib/pstore/version.rb b/lib/pstore/version.rb deleted file mode 100644 index 0e7a3fbd15..0000000000 --- a/lib/pstore/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -class PStore - VERSION = "0.1.0" -end diff --git a/lib/singleton.rb b/lib/singleton.rb index 32be573a78..8d53323ad4 100644 --- a/lib/singleton.rb +++ b/lib/singleton.rb @@ -92,6 +92,8 @@ # p a.strip # => nil # module Singleton + VERSION = "0.1.0" + # Raises a TypeError to prevent cloning. def clone raise TypeError, "can't clone instance of singleton #{self.class}" diff --git a/lib/singleton/singleton.gemspec b/lib/singleton/singleton.gemspec index c6a273a839..2f23233ccf 100644 --- a/lib/singleton/singleton.gemspec +++ b/lib/singleton/singleton.gemspec @@ -1,12 +1,15 @@ -begin - require_relative "lib/singleton/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 = "singleton" - spec.version = Singleton::VERSION + spec.name = name + spec.version = version spec.authors = ["Yukihiro Matsumoto"] spec.email = ["matz@ruby-lang.org"] diff --git a/lib/singleton/version.rb b/lib/singleton/version.rb deleted file mode 100644 index 01ab1eb5fa..0000000000 --- a/lib/singleton/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Singleton - VERSION = "0.1.0" -end diff --git a/lib/timeout.rb b/lib/timeout.rb index 62a35169a4..cbe0bc7cdf 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -23,6 +23,8 @@ # Copyright:: (C) 2000 Information-technology Promotion Agency, Japan module Timeout + VERSION = "0.1.0" + # Raised by Timeout.timeout when the block times out. class Error < RuntimeError attr_reader :thread diff --git a/lib/timeout/timeout.gemspec b/lib/timeout/timeout.gemspec index 7b650bdc31..12ac062b6d 100644 --- a/lib/timeout/timeout.gemspec +++ b/lib/timeout/timeout.gemspec @@ -1,12 +1,15 @@ -begin - require_relative "lib/timeout/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 = "timeout" - spec.version = Timeout::VERSION + spec.name = name + spec.version = version spec.authors = ["Yukihiro Matsumoto"] spec.email = ["matz@ruby-lang.org"] diff --git a/lib/timeout/version.rb b/lib/timeout/version.rb deleted file mode 100644 index 39fc6eec5f..0000000000 --- a/lib/timeout/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Timeout - VERSION = "0.1.0" -end diff --git a/lib/tracer.rb b/lib/tracer.rb index c1540b8d23..81bda189c2 100644 --- a/lib/tracer.rb +++ b/lib/tracer.rb @@ -60,6 +60,7 @@ # by Keiju ISHITSUKA(keiju@ishitsuka.com) # class Tracer + VERSION = "0.1.0" class << self # display additional debug information (defaults to false) diff --git a/lib/tracer/tracer.gemspec b/lib/tracer/tracer.gemspec index 9eab333f79..63e845cf84 100644 --- a/lib/tracer/tracer.gemspec +++ b/lib/tracer/tracer.gemspec @@ -1,13 +1,15 @@ -begin - require_relative "lib/tracer/version" -rescue LoadError - # for 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 = "tracer" - spec.version = Tracer::VERSION + spec.name = name + spec.version = version spec.authors = ["Keiju ISHITSUKA"] spec.email = ["keiju@ruby-lang.org"] diff --git a/lib/tracer/version.rb b/lib/tracer/version.rb deleted file mode 100644 index f1b6dcd094..0000000000 --- a/lib/tracer/version.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -class Tracer - VERSION = "0.1.0" -end diff --git a/lib/weakref.rb b/lib/weakref.rb index 824d4016e1..3b681a529c 100644 --- a/lib/weakref.rb +++ b/lib/weakref.rb @@ -17,6 +17,7 @@ require "delegate" # class WeakRef < Delegator + VERSION = "0.1.0" ## # RefError is raised when a referenced object has been recycled by the diff --git a/lib/weakref/version.rb b/lib/weakref/version.rb deleted file mode 100644 index 893da80753..0000000000 --- a/lib/weakref/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Weakref - VERSION = "0.1.0" -end diff --git a/lib/weakref/weakref.gemspec b/lib/weakref/weakref.gemspec index 886ae13d9f..a7c83a53e7 100644 --- a/lib/weakref/weakref.gemspec +++ b/lib/weakref/weakref.gemspec @@ -1,10 +1,15 @@ -lib = File.expand_path("lib", __dir__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "weakref/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 = "weakref" - spec.version = Weakref::VERSION + spec.name = name + spec.version = version spec.authors = ["Yukihiro Matsumoto"] spec.email = ["matz@ruby-lang.org"] -- cgit v1.2.3