Class: Gem::Commands::DirCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::DirCommand
- Includes:
- VersionOption
- Defined in:
- lib/rubygems/commands/dir_command.rb
Overview
OpenCommand will open a gem’s source path
Instance Method Summary collapse
-
#arguments ⇒ Object
:nodoc:.
- #dir_gem(path) ⇒ Object
- #execute ⇒ Object
- #get_path(name) ⇒ Object
-
#initialize ⇒ DirCommand
constructor
A new instance of DirCommand.
Constructor Details
#initialize ⇒ DirCommand
Returns a new instance of DirCommand.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rubygems/commands/dir_command.rb', line 11 def initialize super 'dir', "Prints the install directory of the selected gem", :command => nil, :version=> Gem::Requirement.default, :latest=> false add_option('-l', '--latest', 'If there are multiple versions, open the latest') do |value, | [:latest] = true end add_version_option end |
Instance Method Details
#arguments ⇒ Object
:nodoc:
25 26 27 |
# File 'lib/rubygems/commands/dir_command.rb', line 25 def arguments # :nodoc: "GEMNAME gem to use" end |
#dir_gem(path) ⇒ Object
55 56 57 |
# File 'lib/rubygems/commands/dir_command.rb', line 55 def dir_gem(path) puts path end |
#execute ⇒ Object
29 30 31 32 33 34 |
# File 'lib/rubygems/commands/dir_command.rb', line 29 def execute name = get_one_gem_name path = get_path(name) dir_gem(path) if path end |
#get_path(name) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubygems/commands/dir_command.rb', line 36 def get_path(name) dep = Gem::Dependency.new name, [:version] specs = Gem.source_index.search dep if specs.length == 0 say "Could not find '#{name}'" return nil elsif specs.length == 1 || [:latest] return specs.last.full_gem_path else choices = specs.map{|s|"#{s.name} #{s.version}"} c,i = choose_from_list "Use which gem?", choices return specs[i].full_gem_path if i end end |