Class: Gem::Commands::MateCommand

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

Instance Method Summary collapse

Constructor Details

#initializeMateCommand

Returns a new instance of MateCommand.



9
10
11
12
13
# File 'lib/rubygems/commands/mate_command.rb', line 9

def initialize
  super 'mate', 'open a gem in TextMate',
   :version => Gem::Requirement.default
  add_version_option
end

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubygems/commands/mate_command.rb', line 15

def execute
  gem_name = get_one_gem_name
  dep = Gem::Dependency.new gem_name, options[:version]
  specs = Gem::SourceIndex.from_installed_gems.search dep
  
  if specs.empty?
    fail "Failed to find gem #{gem_name} version #{options[:version]}!"
  end
  
  specs.sort! do |a,b|
    b.version <=> a.version
  end
  
  puts "Opening in TextMate: " + specs.first.full_gem_path
  %x[ mate "#{specs.first.full_gem_path}" ]
end