Skip to content

Commit

Permalink
Add require parameter to bundle add`
Browse files Browse the repository at this point in the history
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
  • Loading branch information
boardfish committed Dec 7, 2021
1 parent 6a655a6 commit a4f2f8a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions bundler/lib/bundler/cli.rb
Expand Up @@ -367,6 +367,7 @@ def binstubs(*gems)
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 =>
Expand Down
9 changes: 8 additions & 1 deletion bundler/lib/bundler/injector.rb
Expand Up @@ -113,8 +113,9 @@ def build_gem_lines(conservative_versioning)
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

Expand Down Expand Up @@ -269,5 +270,11 @@ def cross_check_for_errors(gemfile_path, original_deps, removed_deps, initial_ge
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
12 changes: 12 additions & 0 deletions bundler/spec/commands/add_spec.rb
Expand Up @@ -68,6 +68,18 @@
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'"
Expand Down

0 comments on commit a4f2f8a

Please sign in to comment.