Class: Gem::Commands::WhoisCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
GemcutterUtilities
Defined in:
lib/rubygems/commands/whois_command.rb

Instance Method Summary collapse

Constructor Details

#initializeWhoisCommand

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

#argumentsObject



12
13
14
# File 'lib/rubygems/commands/whois_command.rb', line 12

def arguments
  "GEM       name of gem"
end

#descriptionObject



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

#executeObject



24
25
26
# File 'lib/rubygems/commands/whois_command.rb', line 24

def execute
  whois get_one_gem_name
end

#usageObject



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