diff options
Diffstat (limited to 'lib/bundler/cli')
-rw-r--r-- | lib/bundler/cli/add.rb | 42 | ||||
-rw-r--r-- | lib/bundler/cli/inject.rb | 14 |
2 files changed, 13 insertions, 43 deletions
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 |