Class: Gem::Commands::VersionsCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::VersionsCommand
- Defined in:
- lib/rubygems/commands/versions_command.rb
Instance Method Summary collapse
- #arguments ⇒ Object
- #description ⇒ Object
- #execute ⇒ Object
-
#initialize ⇒ VersionsCommand
constructor
A new instance of VersionsCommand.
- #local_versions(name) ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ VersionsCommand
Returns a new instance of VersionsCommand.
5 6 7 |
# File 'lib/rubygems/commands/versions_command.rb', line 5 def initialize super 'versions', description end |
Instance Method Details
#arguments ⇒ Object
13 14 15 |
# File 'lib/rubygems/commands/versions_command.rb', line 13 def arguments 'GEMNAME exact name of gem for which to list versions' end |
#description ⇒ Object
9 10 11 |
# File 'lib/rubygems/commands/versions_command.rb', line 9 def description 'List all published versions of a gem. Versions you have installed locally are asterisked.' end |
#execute ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rubygems/commands/versions_command.rb', line 21 def execute name = get_one_gem_name locals = local_versions name begin response = ::HTTParty.get "https://rubygems.org/api/v1/versions/#{name}.json" rescue MultiJson::DecodeError # Rubygems' invalid JSON response of plain text trips up HTTParty. puts "Unable to find #{name}." return end if response.code == 200 remotes = response.map { |item| item['number'] }.map { |v| Gem::Version.create v }.sort.reverse.map &:to_s remotes.each do |r| puts "#{locals.include?(r) ? '*' : ' '} #{r}" end else puts "Unable to find #{name}." end end |
#local_versions(name) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/rubygems/commands/versions_command.rb', line 42 def local_versions(name) specs = if Gem::Specification.respond_to? :find_all_by_name Gem::Specification.find_all_by_name name else dep = Gem::Dependency.new name, Gem::Requirement.default Gem.source_index.search dep end specs.map { |spec| spec.version.to_s } end |
#usage ⇒ Object
17 18 19 |
# File 'lib/rubygems/commands/versions_command.rb', line 17 def usage "#{program_name} GEMNAME" end |