summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2018-03-20 21:18:08 -0700
committerSamuel Giddins <segiddins@segiddins.me>2018-04-30 22:01:46 -0700
commit225c68ee29b29a7f706e3cfb36538a9f940cbe65 (patch)
tree4c13c66d9a85070f9d874e3eb67063b296b67ab9
parent0c5d3b8c1f391aa5175321675ecd91ee6a1f231b (diff)
downloadbundler-segiddins/bundle-gem-version-file.tar.gz
[CLI::Gem] Store the VERSION in a separate filesegiddins/bundle-gem-version-file
This way, the gemspec does not need to change the load path
-rw-r--r--lib/bundler/cli/gem.rb3
-rw-r--r--lib/bundler/templates/newgem/VERSION1
-rw-r--r--lib/bundler/templates/newgem/lib/newgem/version.rb.tt2
-rw-r--r--lib/bundler/templates/newgem/newgem.gemspec.tt8
-rw-r--r--spec/commands/newgem_spec.rb16
5 files changed, 19 insertions, 11 deletions
diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb
index 58e2f8a3fd..aad4341f5d 100644
--- a/lib/bundler/cli/gem.rb
+++ b/lib/bundler/cli/gem.rb
@@ -66,10 +66,11 @@ module Bundler
"lib/newgem.rb.tt" => "lib/#{namespaced_path}.rb",
"lib/newgem/version.rb.tt" => "lib/#{namespaced_path}/version.rb",
"newgem.gemspec.tt" => "#{name}.gemspec",
+ "VERSION" => "VERSION",
"Rakefile.tt" => "Rakefile",
"README.md.tt" => "README.md",
"bin/console.tt" => "bin/console",
- "bin/setup.tt" => "bin/setup"
+ "bin/setup.tt" => "bin/setup",
}
executables = %w[
diff --git a/lib/bundler/templates/newgem/VERSION b/lib/bundler/templates/newgem/VERSION
new file mode 100644
index 0000000000..6c6aa7cb09
--- /dev/null
+++ b/lib/bundler/templates/newgem/VERSION
@@ -0,0 +1 @@
+0.1.0 \ No newline at end of file
diff --git a/lib/bundler/templates/newgem/lib/newgem/version.rb.tt b/lib/bundler/templates/newgem/lib/newgem/version.rb.tt
index 389daf5048..518b4688a4 100644
--- a/lib/bundler/templates/newgem/lib/newgem/version.rb.tt
+++ b/lib/bundler/templates/newgem/lib/newgem/version.rb.tt
@@ -1,7 +1,7 @@
<%- config[:constant_array].each_with_index do |c, i| -%>
<%= " " * i %>module <%= c %>
<%- end -%>
-<%= " " * config[:constant_array].size %>VERSION = "0.1.0"
+<%= " " * config[:constant_array].size %>VERSION = File.read(File.expand_path("<%= "../" * (config[:constant_array].size + 2) + "VERSION" %>", __FILE__)).strip.freeze
<%- (config[:constant_array].size-1).downto(0) do |i| -%>
<%= " " * i %>end
<%- end -%>
diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt
index 116bb5fa62..d29fb6a020 100644
--- a/lib/bundler/templates/newgem/newgem.gemspec.tt
+++ b/lib/bundler/templates/newgem/newgem.gemspec.tt
@@ -1,16 +1,10 @@
<%- if RUBY_VERSION < "2.0.0" -%>
# coding: utf-8
-lib = File.expand_path("../lib", __FILE__)
-<%- else -%>
-lib = File.expand_path("lib", __dir__)
<%- end -%>
-$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
-require "<%= config[:namespaced_path] %>/version"
-
Gem::Specification.new do |spec|
spec.name = <%= config[:name].inspect %>
- spec.version = <%= config[:constant_name] %>::VERSION
+ spec.version = File.read(File.expand_path("../VERSION", __FILE__)).strip
spec.authors = [<%= config[:author].inspect %>]
spec.email = [<%= config[:email].inspect %>]
diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb
index 9f45fb665b..d79162c566 100644
--- a/spec/commands/newgem_spec.rb
+++ b/spec/commands/newgem_spec.rb
@@ -278,7 +278,12 @@ RSpec.describe "bundle gem" do
end
it "starts with version 0.1.0" do
- expect(bundled_app("test_gem/lib/test_gem/version.rb").read).to match(/VERSION = "0.1.0"/)
+ expect(bundled_app("test_gem/VERSION")).to read_as("0.1.0")
+ expect(bundled_app("test_gem/lib/test_gem/version.rb")).to read_as(strip_whitespace(<<-RUBY))
+ module TestGem
+ VERSION = File.read(File.expand_path("../../../VERSION", __FILE__)).strip.freeze
+ end
+ RUBY
end
it "does not nest constants" do
@@ -572,7 +577,14 @@ RSpec.describe "bundle gem" do
end
it "starts with version 0.1.0" do
- expect(bundled_app("test-gem/lib/test/gem/version.rb").read).to match(/VERSION = "0.1.0"/)
+ expect(bundled_app("test-gem/VERSION")).to read_as("0.1.0")
+ expect(bundled_app("test-gem/lib/test/gem/version.rb")).to read_as(strip_whitespace(<<-RUBY))
+ module Test
+ module Gem
+ VERSION = File.read(File.expand_path("../../../../VERSION", __FILE__)).strip.freeze
+ end
+ end
+ RUBY
end
it "nests constants so they work" do