summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorColby Swandale <colby@taplaboratories.com>2017-06-04 20:36:49 +1000
committerColby Swandale <colby@taplaboratories.com>2017-06-04 20:41:57 +1000
commit581f0cde1a60e1a6c300ae4028acf476723ca2ce (patch)
treefa9366dd84503027236ae302da9f29af062c11c0 /lib
parent2e46e6705770e5a4685b1f3d3fbbe60f957599ae (diff)
downloadbundler-581f0cde1a60e1a6c300ae4028acf476723ca2ce.tar.gz
generate gems.rb in bundle init with feature flag
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/cli/init.rb18
-rw-r--r--lib/bundler/feature_flag.rb1
-rw-r--r--lib/bundler/settings.rb1
-rw-r--r--lib/bundler/templates/gems.rb5
4 files changed, 19 insertions, 6 deletions
diff --git a/lib/bundler/cli/init.rb b/lib/bundler/cli/init.rb
index 8ffd1db41a..ae5d68853e 100644
--- a/lib/bundler/cli/init.rb
+++ b/lib/bundler/cli/init.rb
@@ -7,8 +7,8 @@ module Bundler
end
def run
- if File.exist?("Gemfile")
- Bundler.ui.error "Gemfile already exists at #{SharedHelpers.pwd}/Gemfile"
+ if File.exist?(gemfile)
+ Bundler.ui.error "#{gemfile} already exists at #{SharedHelpers.pwd}/#{gemfile}"
exit 1
end
@@ -21,15 +21,21 @@ module Bundler
spec = Bundler.load_gemspec_uncached(gemspec)
- puts "Writing new Gemfile to #{SharedHelpers.pwd}/Gemfile"
- File.open("Gemfile", "wb") do |file|
+ puts "Writing new Gemfile to #{SharedHelpers.pwd}/#{gemfile}"
+ File.open(gemfile, "wb") do |file|
file << "# Generated from #{gemspec}\n"
file << spec.to_gemfile
end
else
- puts "Writing new Gemfile to #{SharedHelpers.pwd}/Gemfile"
- FileUtils.cp(File.expand_path("../../templates/Gemfile", __FILE__), "Gemfile")
+ puts "Writing new #{gemfile} to #{SharedHelpers.pwd}/#{gemfile}"
+ FileUtils.cp(File.expand_path("../../templates/#{gemfile}", __FILE__), gemfile)
end
end
+
+ private
+
+ def gemfile
+ @gemfile ||= Bundler.feature_flag.new_gemfile_name? ? "gems.rb" : "Gemfile"
+ end
end
end
diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb
index 5ee69f538c..a75bcfb5f7 100644
--- a/lib/bundler/feature_flag.rb
+++ b/lib/bundler/feature_flag.rb
@@ -18,6 +18,7 @@ module Bundler
settings_flag(:only_update_to_newer_versions) { bundler_2_mode? }
settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") }
settings_flag(:error_on_stderr) { bundler_2_mode? }
+ settings_flag(:new_gemfile_name) { bundler_2_mode? }
def initialize(bundler_version)
@bundler_version = Gem::Version.create(bundler_version)
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index 68a7add942..d5927afd87 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -28,6 +28,7 @@ module Bundler
plugins
silence_root_warning
error_on_stderr
+ new_gemfile_name
].freeze
NUMBER_KEYS = %w[
diff --git a/lib/bundler/templates/gems.rb b/lib/bundler/templates/gems.rb
new file mode 100644
index 0000000000..a6ef23ba3e
--- /dev/null
+++ b/lib/bundler/templates/gems.rb
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+# A sample gems.rb
+source "https://rubygems.org"
+
+# gems "rails"