diff options
author | Boggs <hello.boggs@gmail.com> | 2016-06-09 12:08:53 +0800 |
---|---|---|
committer | Boggs <hello.boggs@gmail.com> | 2016-06-13 16:54:58 +0800 |
commit | 2e8d6ffe2351bd8be0ff6dbaf32bde2b7b1d6ff4 (patch) | |
tree | 43b1c02fa35d047ba3c4f5cae6dfd0afa0a74dcb /lib/bundler/cli | |
parent | 928dfee35ab96112fbc05a0ae88492c91361dfab (diff) | |
download | bundler-2e8d6ffe2351bd8be0ff6dbaf32bde2b7b1d6ff4.tar.gz |
Use Bundler.definition to fetch last version number
Diffstat (limited to 'lib/bundler/cli')
-rw-r--r-- | lib/bundler/cli/add.rb | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb index 117ef6167c..4ccfee38f4 100644 --- a/lib/bundler/cli/add.rb +++ b/lib/bundler/cli/add.rb @@ -1,10 +1,13 @@ # frozen_string_literal: true +require "bundler/cli/common" require "net/http" require "yaml" module Bundler class CLI::Add - def initialize(name, version) + attr_reader :options, :name, :version + def initialize(options, name, version) + @options = options @name = name @version = version || last_version_number end @@ -20,17 +23,20 @@ module Bundler private def last_version_number - uri = URI.parse("https://rubygems.org/api/v1/gems/#{@name}.yaml") - response = Net::HTTP.get(uri) - YAML.load(response)["version"] + 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 def output_line - %(|gem "#{@name}", "#{approximate_recommendation}"|) + %(|gem "#{name}", "#{approximate_recommendation}"|) end def approximate_recommendation - Gem::Version.new(@version).approximate_recommendation + Gem::Version.new(version).approximate_recommendation end end end |