diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-29 00:31:52 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-30 19:03:18 +0900 |
commit | b2d96abb42abbe2e01f010ffc9ac51f0f9a50002 (patch) | |
tree | 57791da8a71280c335109916376e13f5e0c63af3 /lib/ostruct | |
parent | cfbae7dae052180e5dde05a27948ae8d779eccab (diff) | |
download | ruby-b2d96abb42abbe2e01f010ffc9ac51f0f9a50002.tar.gz |
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.
Diffstat (limited to 'lib/ostruct')
-rw-r--r-- | lib/ostruct/ostruct.gemspec | 14 | ||||
-rw-r--r-- | lib/ostruct/version.rb | 5 |
2 files changed, 7 insertions, 12 deletions
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 |