Class: Gem::Commands::CdCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
VersionOption, GemToolbox::CommonOptions
Defined in:
lib/rubygems/commands/cd_command.rb

Overview

CdCommand will cd to gem’s source path

Instance Method Summary collapse

Methods included from GemToolbox::CommonOptions

#add_command_option, #add_exact_match_option, #add_latest_version_option, #get_path, #get_spec, #show

Constructor Details

#initializeCdCommand

Returns a new instance of CdCommand.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rubygems/commands/cd_command.rb', line 8

def initialize
  super 'cd', "Change directory to the gem's source directory",
    :command => nil, 
    :version=>  Gem::Requirement.default,
    :latest=>   false
  
  add_command_option
  add_latest_version_option
  add_version_option
  add_exact_match_option
end

Instance Method Details

#argumentsObject

:nodoc:



20
21
22
# File 'lib/rubygems/commands/cd_command.rb', line 20

def arguments # :nodoc:
  "GEMNAME       gem to cd into"
end

#do_cd(path) ⇒ Object



31
32
33
34
35
# File 'lib/rubygems/commands/cd_command.rb', line 31

def do_cd(path)
  app = Appscript.app("Terminal")
  win = app.windows.get.detect { |w| w.properties_.get[:frontmost] }
  win.do_script "cd #{path}", :in => win
end

#executeObject



24
25
26
27
28
29
# File 'lib/rubygems/commands/cd_command.rb', line 24

def execute
  name = get_one_gem_name
  path = get_path(name)
  
  do_cd(path) if path
end