Class: Gem::Commands::HomepageCommand

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

Instance Method Summary collapse

Constructor Details

#initializeHomepageCommand

Returns a new instance of HomepageCommand.



15
16
17
# File 'lib/rubygems/commands/homepage_command.rb', line 15

def initialize
  super "homepage", description
end

Instance Method Details

#argumentsObject



7
8
9
# File 'lib/rubygems/commands/homepage_command.rb', line 7

def arguments
  "GEM    gem's name"
end

#descriptionObject



3
4
5
# File 'lib/rubygems/commands/homepage_command.rb', line 3

def description
  "Open the homepage for this gem"
end

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rubygems/commands/homepage_command.rb', line 19

def execute
  gemname = options[:args].first
  unless gemname
    say "Usage: #{usage}"
    return terminate_interaction
  end
  dep = Gem::Dependency.new(gemname,"> 0")
  if Gem::Specification.respond_to? :find_all_by_name
    spec = Gem::Specification.find_all_by_name(gemname).first
  else
    spec = Gem.source_index.search(dep).first
  end
  if spec.nil?
  #try remote if you didn't find it locally
    fetcher = Gem::SpecFetcher.fetcher
    if fetcher.respond_to? :spec_for_dependency
      t = fetcher.spec_for_dependency(dep).first.last
    else
      t = fetcher.fetch(dep).first
    end
    spec = t.first if t
  end

  if spec
    if spec.homepage and spec.homepage != ""
      Launchy.open(spec.homepage)
    else
      say "No homepage listed in the gemspec for this gem."
      return terminate_interaction
    end
  else
    say "The #{gemname.inspect} gem couldn't be found"
    return terminate_interaction
  end
end

#usageObject



11
12
13
# File 'lib/rubygems/commands/homepage_command.rb', line 11

def usage
  "#{program_name} GEM"
end