Class: Gem::Commands::PathCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::PathCommand
- Defined in:
- lib/rubygems/commands/path_command.rb
Instance Method Summary collapse
- #description ⇒ Object
- #execute ⇒ Object
- #find_gem_path(name) ⇒ Object
-
#initialize ⇒ PathCommand
constructor
A new instance of PathCommand.
Constructor Details
#initialize ⇒ PathCommand
Returns a new instance of PathCommand.
7 8 9 |
# File 'lib/rubygems/commands/path_command.rb', line 7 def initialize super('path', description) end |
Instance Method Details
#description ⇒ Object
3 4 5 |
# File 'lib/rubygems/commands/path_command.rb', line 3 def description 'Find the path for a given gem or require path' end |
#execute ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubygems/commands/path_command.rb', line 11 def execute name, version = extract!([:args]) # find the exact gem if gem_path = find_gem_path(name) say(gem_path) # find the require file elsif path = Gem.find_files("#{name}.rb").first # favor gem first (e.g. rake gem) if gem_path = Gem.path.find{ |p| break $1 if path =~ %r{(#{p}(/[^/]+){2})} } say(gem_path) else say(path) end else alert_error("#{name} not found") terminate_interaction(1) end end |
#find_gem_path(name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rubygems/commands/path_command.rb', line 34 def find_gem_path name gem_path = Gem.path.find do |base| gem_path = $LOAD_PATH.find do |path| platforms = [ 'ruby', sitearch, *univeral_darwin ].map(&Regexp.method(:escape)).join('|') gem_path = path[ %r{\A#{base}/ (?:bundler/)? gems/ #{name}\-[^/-]+(?:\-(?:#{platforms}))?/ }x ] break gem_path if gem_path end break gem_path if gem_path end gem_path.chop if gem_path end |