[前][次][番号順一覧][スレッド一覧]

ruby-changes:70098

From: Simon <ko1@a...>
Date: Wed, 8 Dec 2021 01:49:37 +0900 (JST)
Subject: [ruby-changes:70098] 1b12ebb94e (master): [rubygems/rubygems] Add require parameter to `bundle add``

https://git.ruby-lang.org/ruby.git/commit/?id=1b12ebb94e

From 1b12ebb94e50e16ca9f226e583ee2a3d418402d6 Mon Sep 17 00:00:00 2001
From: Simon Fish <si@m...>
Date: Tue, 26 Oct 2021 17:50:55 +0100
Subject: [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

https://github.com/rubygems/rubygems/commit/a4f2f8ac17
---
 lib/bundler/cli.rb                |  1 +
 lib/bundler/injector.rb           |  9 ++++++++-
 spec/bundler/commands/add_spec.rb | 12 ++++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index d271086b254..9046c0115c9 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -367,6 +367,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/cli.rb#L367
     method_option "version", :aliases => "-v", :type => :string
     method_option "group", :aliases => "-g", :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 "branch", :type => :string
     method_option "skip-install", :type => :boolean, :banner =>
diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb
index 613bda4f844..5e5dfca02ee 100644
--- a/lib/bundler/injector.rb
+++ b/lib/bundler/injector.rb
@@ -113,8 +113,9 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/injector.rb#L113
         source = ", :source => \"#{d.source}\"" unless d.source.nil?
         git = ", :git => \"#{d.git}\"" unless d.git.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
 
@@ -269,5 +270,11 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/injector.rb#L270
     def show_warning(message)
       Bundler.ui.info Bundler.ui.add_color(message, :yellow)
     end
+
+    def convert_autorequire(autorequire)
+      autorequire = autorequire.first
+      return autorequire if autorequire == "false"
+      autorequire.inspect
+    end
   end
 end
diff --git a/spec/bundler/commands/add_spec.rb b/spec/bundler/commands/add_spec.rb
index 4c533652ca6..093ec53fea0 100644
--- a/spec/bundler/commands/add_spec.rb
+++ b/spec/bundler/commands/add_spec.rb
@@ -68,6 +68,18 @@ RSpec.describe "bundle add" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/add_spec.rb#L68
     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
     it "adds dependency for the specified group" do
       bundle "add 'foo' --group='development'"
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]