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 | |
parent | 928dfee35ab96112fbc05a0ae88492c91361dfab (diff) | |
download | bundler-2e8d6ffe2351bd8be0ff6dbaf32bde2b7b1d6ff4.tar.gz |
Use Bundler.definition to fetch last version number
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/cli.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/add.rb | 18 |
2 files changed, 13 insertions, 7 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index d237c4fd..88ad62a2 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -447,7 +447,7 @@ module Bundler desc "add GEM [VERSION]", "Add the named gem to the bottom of Gemfile" def add(name, version = nil) require "bundler/cli/add" - Add.new(name, version).run + Add.new(options, name, version).run end if Bundler.settings[:plugins] diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb index 117ef616..4ccfee38 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 |