1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Add require parameter to bundle add`

Test and ensure "false" is handled

Don't use yield_self to operate on autorequire

Remove duplicate autorequire

Add banner to require option

Don't use json to break down require params

Pass linter

a4f2f8ac17
This commit is contained in:
Simon Fish 2021-10-26 17:50:55 +01:00 committed by git
parent 26303c31f0
commit 1b12ebb94e
3 changed files with 21 additions and 1 deletions

View file

@ -367,6 +367,7 @@ module Bundler
method_option "version", :aliases => "-v", :type => :string method_option "version", :aliases => "-v", :type => :string
method_option "group", :aliases => "-g", :type => :string method_option "group", :aliases => "-g", :type => :string
method_option "source", :aliases => "-s", :type => :string method_option "source", :aliases => "-s", :type => :string
method_option "require", :aliases => "-r", :type => :string, :banner => "Adds require path to gem. Provide false, or a path as a string."
method_option "git", :type => :string method_option "git", :type => :string
method_option "branch", :type => :string method_option "branch", :type => :string
method_option "skip-install", :type => :boolean, :banner => method_option "skip-install", :type => :boolean, :banner =>

View file

@ -113,8 +113,9 @@ module Bundler
source = ", :source => \"#{d.source}\"" unless d.source.nil? source = ", :source => \"#{d.source}\"" unless d.source.nil?
git = ", :git => \"#{d.git}\"" unless d.git.nil? git = ", :git => \"#{d.git}\"" unless d.git.nil?
branch = ", :branch => \"#{d.branch}\"" unless d.branch.nil? branch = ", :branch => \"#{d.branch}\"" unless d.branch.nil?
require_path = ", :require => #{convert_autorequire(d.autorequire)}" unless d.autorequire.nil?
%(gem #{name}#{requirement}#{group}#{source}#{git}#{branch}) %(gem #{name}#{requirement}#{group}#{source}#{git}#{branch}#{require_path})
end.join("\n") end.join("\n")
end end
@ -269,5 +270,11 @@ module Bundler
def show_warning(message) def show_warning(message)
Bundler.ui.info Bundler.ui.add_color(message, :yellow) Bundler.ui.info Bundler.ui.add_color(message, :yellow)
end end
def convert_autorequire(autorequire)
autorequire = autorequire.first
return autorequire if autorequire == "false"
autorequire.inspect
end
end end
end end

View file

@ -68,6 +68,18 @@ RSpec.describe "bundle add" do
end end
end end
describe "with --require" do
it "adds the require param for the gem" do
bundle "add 'foo' --require=foo/engine"
expect(bundled_app_gemfile.read).to match(%r{gem "foo",(?: .*,) :require => "foo\/engine"})
end
it "converts false to a boolean" do
bundle "add 'foo' --require=false"
expect(bundled_app_gemfile.read).to match(/gem "foo",(?: .*,) :require => false/)
end
end
describe "with --group" do describe "with --group" do
it "adds dependency for the specified group" do it "adds dependency for the specified group" do
bundle "add 'foo' --group='development'" bundle "add 'foo' --group='development'"