summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bundler/cli.rb1
-rw-r--r--lib/bundler/injector.rb9
-rw-r--r--spec/bundler/commands/add_spec.rb12
3 files changed, 21 insertions, 1 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index d271086b25..9046c0115c 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -367,6 +367,7 @@ module Bundler
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 613bda4f84..5e5dfca02e 100644
--- a/lib/bundler/injector.rb
+++ b/lib/bundler/injector.rb
@@ -113,8 +113,9 @@ module Bundler
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
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 4c533652ca..093ec53fea 100644
--- a/spec/bundler/commands/add_spec.rb
+++ b/spec/bundler/commands/add_spec.rb
@@ -68,6 +68,18 @@ RSpec.describe "bundle add" do
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'"