diff options
author | Boggs <hello.boggs@gmail.com> | 2016-06-15 16:55:32 +0800 |
---|---|---|
committer | Boggs <hello.boggs@gmail.com> | 2016-06-15 16:55:32 +0800 |
commit | 8bb7f53865223154f5d92e3d48bbf49273cbfaca (patch) | |
tree | 8dfbd29bbb21427ebcf7197f75e0d8a08de7dc9f | |
parent | 654e6bb2eaa3b55e2f205345098fb736086d1a41 (diff) | |
download | bundler-8bb7f53865223154f5d92e3d48bbf49273cbfaca.tar.gz |
Remove add class, add `last_version_number` method in `inject.rb`
-rw-r--r-- | lib/bundler/cli.rb | 6 | ||||
-rw-r--r-- | lib/bundler/cli/add.rb | 42 | ||||
-rw-r--r-- | lib/bundler/cli/inject.rb | 14 |
3 files changed, 17 insertions, 45 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 2ecd04b9..890a0ac3 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -446,8 +446,10 @@ module Bundler desc "add GEM [VERSION]", "Add the specified gem to the bottom of Gemfile" def add(name, version = nil, *gems) - require "bundler/cli/add" - Add.new(options, name, version, gems).run + # require "bundler/cli/add" + # Add.new(options, name, version, gems).run + require "bundler/cli/inject" + Inject.new(options, name, version, gems).run end if Bundler.settings[:plugins] diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb deleted file mode 100644 index 36864fed..00000000 --- a/lib/bundler/cli/add.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true -require "bundler/cli/common" -module Bundler - class CLI::Add - attr_reader :options, :name, :version, :gems - def initialize(options, name, version, gems) - @options = options - @name = name - @version = version || last_version_number - @gems = gems - end - - def run - gems.unshift(version).unshift(name) - - deps = [] - gems.each_slice(2) do |gem_name, gem_version| - deps << Bundler::Dependency.new(gem_name, gem_version) - end - - added = Injector.inject(deps) - - if added.any? - Bundler.ui.confirm "Added to Gemfile:" - Bundler.ui.confirm added.map {|g| " #{g}" }.join("\n") - else - Bundler.ui.confirm "All specified gems are already present in the Gemfile" - end - end - - private - - def last_version_number - definition = Bundler.definition(true) - definition.resolve_remotely! - specs = definition.index[name].sort_by(&:version) - spec = specs.delete_if {|b| b.respond_to?(:version) && b.version.prerelease? } - spec = specs.last - spec.version.to_s - end - end -end diff --git a/lib/bundler/cli/inject.rb b/lib/bundler/cli/inject.rb index e319feb2..2e768b74 100644 --- a/lib/bundler/cli/inject.rb +++ b/lib/bundler/cli/inject.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true +require "bundler/cli/common" module Bundler class CLI::Inject attr_reader :options, :name, :version, :gems def initialize(options, name, version, gems) @options = options @name = name - @version = version + @version = version || last_version_number @gems = gems end @@ -29,5 +30,16 @@ module Bundler Bundler.ui.confirm "All injected gems were already present in the Gemfile" end end + + private + + def last_version_number + definition = Bundler.definition(true) + definition.resolve_remotely! + specs = definition.index[name].sort_by(&:version) + spec = specs.delete_if {|b| b.respond_to?(:version) && b.version.prerelease? } + spec = specs.last + spec.version.to_s + end end end |