Class: MyPath::Handler::Gem

Inherits:
MyPath::Handler show all
Defined in:
lib/mypath/handler/gem.rb

Instance Attribute Summary

Attributes inherited from MyPath::Handler

#path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MyPath::Handler

clean_path, for, inherited, #initialize

Constructor Details

This class inherits a constructor from MyPath::Handler

Class Method Details

.can_handle?(path) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/mypath/handler/gem.rb', line 4

def self.can_handle?(path)
  clean_path(path) =~ /\/gems\//
end

.local_gem_pathsObject



8
9
10
# File 'lib/mypath/handler/gem.rb', line 8

def self.local_gem_paths
  @local_gem_paths ||= ::Gem.path.collect{ |g| File.join(g, 'gems') }
end

Instance Method Details

#local_pathObject



12
13
14
15
16
# File 'lib/mypath/handler/gem.rb', line 12

def local_path
  remote_gem_path = /.*?\/gems\/.*?([^\/]+?-\d\..*)/.match(self.path)[1]
  joined = self.class.local_gem_paths.collect{|g| File.join(g, remote_gem_path)}
  Dir[*joined].first
end