diff options
author | Dennis Suratna <dennis.suratna@gmail.com> | 2017-03-03 10:12:19 -0800 |
---|---|---|
committer | Dennis Suratna <dennis.suratna@gmail.com> | 2017-04-10 15:46:27 +0700 |
commit | aa737807c0a2e276b22f005011deea1a5b5378a1 (patch) | |
tree | 77c11561a775ae5b3a81067251e958c298c29c2d | |
parent | a95d646e060a5f8ae36589673e369fdb37548a31 (diff) | |
download | bundler-aa737807c0a2e276b22f005011deea1a5b5378a1.tar.gz |
Add command: Handle multiple versions
-rw-r--r-- | lib/bundler/cli.rb | 1 | ||||
-rw-r--r-- | lib/bundler/cli/add.rb | 4 | ||||
-rw-r--r-- | lib/bundler/injector.rb | 2 | ||||
-rw-r--r-- | spec/commands/add_spec.rb | 6 |
4 files changed, 10 insertions, 3 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index bc9740fc9c..47c8bf22c1 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -276,7 +276,6 @@ module Bundler method_option "group", :aliases => "-g", :type => :string method_option "source", :aliases => "-s", :type => :string - map "a" => "add" def add(gem_name) require "bundler/cli/add" Add.new(options.dup, gem_name).run diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb index baf27c45d0..888ce4e226 100644 --- a/lib/bundler/cli/add.rb +++ b/lib/bundler/cli/add.rb @@ -10,7 +10,9 @@ module Bundler end def run - dependency = Bundler::Dependency.new(@gem_name, @options[:version], @options) + dependency = Bundler::Dependency.new(@gem_name, nil, @options) + dependency.instance_variable_set(:@requirement, Gem::Requirement.new(@options[:version].split(",").map(&:strip))) unless @options[:version].nil? + Injector.inject([dependency], :conservative_versioning => @options[:version].nil?) # Perform conservative versioning only when version is not specified Installer.install(Bundler.root, Bundler.definition) end diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index f4043b1fc9..df96727e19 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -63,7 +63,7 @@ module Bundler version = @definition.specs[d.name][0].version requirement = ", '#{conservative_version(version)}'" else - requirement = ", '#{d.requirement}'" + requirement = ", #{d.requirement.as_list.map{|k| "'#{k}'"}.join(", ")}" end if d.groups != Array(:default) diff --git a/spec/commands/add_spec.rb b/spec/commands/add_spec.rb index 6192d5fa48..fce9599d14 100644 --- a/spec/commands/add_spec.rb +++ b/spec/commands/add_spec.rb @@ -36,6 +36,12 @@ RSpec.describe "bundle add" do expect(bundled_app("Gemfile").read).to match(/gem 'foo', '~> 1.0'/) expect(the_bundle).to include_gems "foo 1.1" end + + it "adds multiple version constraints when specified" do + bundle "add 'foo' --version='< 3.0, > 1.1'" + expect(bundled_app("Gemfile").read).to match(/gem 'foo', '< 3.0', '> 1.1'/) + expect(the_bundle).to include_gems "foo 2.0" + end end describe "with --group" do |