Class: Gem::Commands::WhoisCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::WhoisCommand
- Includes:
- GemcutterUtilities
- Defined in:
- lib/rubygems/commands/whois_command.rb
Instance Method Summary collapse
- #arguments ⇒ Object
- #description ⇒ Object
- #execute ⇒ Object
-
#initialize ⇒ WhoisCommand
constructor
A new instance of WhoisCommand.
- #usage ⇒ Object
- #whois(gem_name) ⇒ Object
- #with_response(resp) ⇒ Object
Constructor Details
#initialize ⇒ WhoisCommand
Returns a new instance of WhoisCommand.
20 21 22 |
# File 'lib/rubygems/commands/whois_command.rb', line 20 def initialize super 'whois', description end |
Instance Method Details
#arguments ⇒ Object
12 13 14 |
# File 'lib/rubygems/commands/whois_command.rb', line 12 def arguments "GEM name of gem" end |
#description ⇒ Object
8 9 10 |
# File 'lib/rubygems/commands/whois_command.rb', line 8 def description 'Perform a whois lookup based on a gem name so you can see if it is available or not' end |
#execute ⇒ Object
24 25 26 |
# File 'lib/rubygems/commands/whois_command.rb', line 24 def execute whois get_one_gem_name end |
#usage ⇒ Object
16 17 18 |
# File 'lib/rubygems/commands/whois_command.rb', line 16 def usage "#{program_name} GEM" end |
#whois(gem_name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rubygems/commands/whois_command.rb', line 28 def whois(gem_name) response = rubygems_api_request(:get, "api/v1/gems/#{gem_name}.json") do |request| request.set_form_data("gem_name" => gem_name) end with_response(response) do |resp| json = Crack::JSON.parse(resp.body) puts <<-STR.unindent gem name: #{json['name']} owners: #{json['authors']} info: #{json['info']} version: #{json['version']} downloads: #{json['downloads']} STR end end |
#with_response(resp) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rubygems/commands/whois_command.rb', line 47 def with_response(resp) case resp when Net::HTTPSuccess block_given? ? yield(resp) : say(resp.body) else if resp.body == 'This rubygem could not be found.' puts '','Gem not found. It will be mine. Oh yes. It will be mine. *sinister laugh*','' else say resp.body end end end |