Skip to content

Commit

Permalink
Merge pull request #7557 from thedavemarshall/bundler_cli_gem_glob
Browse files Browse the repository at this point in the history
Add `--glob` flag to `bundle add`
  • Loading branch information
deivid-rodriguez committed Apr 12, 2024
2 parents aef779a + 6d2cf95 commit 153e98a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions bundler/lib/bundler/cli.rb
Expand Up @@ -347,6 +347,7 @@ def binstubs(*gems)
method_option "github", type: :string
method_option "branch", type: :string
method_option "ref", type: :string
method_option "glob", type: :string, banner: "The location of a dependency's .gemspec, expanded within Ruby (single quotes recommended)"
method_option "skip-install", type: :boolean, banner: "Adds gem to the Gemfile but does not install it"
method_option "optimistic", type: :boolean, banner: "Adds optimistic declaration of version to gem"
method_option "strict", type: :boolean, banner: "Adds strict declaration of version to gem"
Expand Down
3 changes: 2 additions & 1 deletion bundler/lib/bundler/dependency.rb
Expand Up @@ -7,7 +7,7 @@
module Bundler
class Dependency < Gem::Dependency
attr_reader :autorequire
attr_reader :groups, :platforms, :gemfile, :path, :git, :github, :branch, :ref
attr_reader :groups, :platforms, :gemfile, :path, :git, :github, :branch, :ref, :glob

ALL_RUBY_VERSIONS = (18..27).to_a.concat((30..34).to_a).freeze
PLATFORM_MAP = {
Expand Down Expand Up @@ -39,6 +39,7 @@ def initialize(name, version, options = {}, &blk)
@github = options["github"]
@branch = options["branch"]
@ref = options["ref"]
@glob = options["glob"]
@platforms = Array(options["platforms"])
@env = options["env"]
@should_include = options.fetch("should_include", true)
Expand Down
3 changes: 2 additions & 1 deletion bundler/lib/bundler/injector.rb
Expand Up @@ -120,9 +120,10 @@ def build_gem_lines(conservative_versioning)
github = ", :github => \"#{d.github}\"" unless d.github.nil?
branch = ", :branch => \"#{d.branch}\"" unless d.branch.nil?
ref = ", :ref => \"#{d.ref}\"" unless d.ref.nil?
glob = ", :glob => \"#{d.glob}\"" unless d.glob.nil?
require_path = ", :require => #{convert_autorequire(d.autorequire)}" unless d.autorequire.nil?

%(gem #{name}#{requirement}#{group}#{source}#{path}#{git}#{github}#{branch}#{ref}#{require_path})
%(gem #{name}#{requirement}#{group}#{source}#{path}#{git}#{github}#{branch}#{ref}#{glob}#{require_path})
end.join("\n")
end

Expand Down
55 changes: 55 additions & 0 deletions bundler/spec/commands/add_spec.rb
Expand Up @@ -175,6 +175,61 @@
end
end

describe "with --git and --glob" do
it "adds dependency with specified git source" do
bundle "add foo --git=#{lib_path("foo-2.0")} --glob='./*.gemspec'"

expect(bundled_app_gemfile.read).to match(%r{gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}", :glob => "\./\*\.gemspec"})
expect(the_bundle).to include_gems "foo 2.0"
end
end

describe "with --git and --branch and --glob" do
before do
update_git "foo", "2.0", branch: "test"
end

it "adds dependency with specified git source and branch" do
bundle "add foo --git=#{lib_path("foo-2.0")} --branch=test --glob='./*.gemspec'"

expect(bundled_app_gemfile.read).to match(%r{gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}", :branch => "test", :glob => "\./\*\.gemspec"})
expect(the_bundle).to include_gems "foo 2.0"
end
end

describe "with --git and --ref and --glob" do
it "adds dependency with specified git source and branch" do
bundle "add foo --git=#{lib_path("foo-2.0")} --ref=#{revision_for(lib_path("foo-2.0"))} --glob='./*.gemspec'"

expect(bundled_app_gemfile.read).to match(%r{gem "foo", "~> 2\.0", :git => "#{lib_path("foo-2.0")}", :ref => "#{revision_for(lib_path("foo-2.0"))}", :glob => "\./\*\.gemspec"})
expect(the_bundle).to include_gems "foo 2.0"
end
end

describe "with --github and --glob" do
it "adds dependency with specified github source", :realworld do
bundle "add rake --github=ruby/rake --glob='./*.gemspec'"

expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :glob => "\.\/\*\.gemspec"})
end
end

describe "with --github and --branch --and glob" do
it "adds dependency with specified github source and branch", :realworld do
bundle "add rake --github=ruby/rake --branch=master --glob='./*.gemspec'"

expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :branch => "master", :glob => "\.\/\*\.gemspec"})
end
end

describe "with --github and --ref and --glob" do
it "adds dependency with specified github source and ref", :realworld do
bundle "add rake --github=ruby/rake --ref=5c60da8 --glob='./*.gemspec'"

expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :ref => "5c60da8", :glob => "\.\/\*\.gemspec"})
end
end

describe "with --skip-install" do
it "adds gem to Gemfile but is not installed" do
bundle "add foo --skip-install --version=2.0"
Expand Down

0 comments on commit 153e98a

Please sign in to comment.