Module: Gem

Defined in:
lib/reverse_require/extensions/rubygems.rb

Class Method Summary collapse

Class Method Details

.find_files_for(gem, path) ⇒ Object

Find all files that end with the specified path, from within RubyGems that depend on the specified gem.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/reverse_require/extensions/rubygems.rb', line 8

def self.find_files_for(gem,path)
  if (spec = Gem.loaded_specs[gem])
    version = spec.version
  else
    version = nil
  end

  dep = Gem.source_index.find_name(gem,version).first

  dep.dependent_gems.map { |deps|
    Gem.searcher.matching_files deps.first, path
  }.flatten
end

.find_resources(path) ⇒ Object

Find resources that end with the specified path from all RubyGems.

Gem.find_resources 'static/template.erb'
# => [...]


28
29
30
31
32
# File 'lib/reverse_require/extensions/rubygems.rb', line 28

def self.find_resources(path)
  find_files(File.join('..',path)).map do |gem_path|
    File.expand_path(gem_path)
  end
end

.find_resources_for(gem, path) ⇒ Object

Find resources that end with the specified path, from within RubyGems that depend on the specified gem.

Gem.find_resources_for 'statix', 'static/xsl/page.xsl'
# => [...]


41
42
43
44
45
# File 'lib/reverse_require/extensions/rubygems.rb', line 41

def self.find_resources_for(gem,path)
  find_files_for(gem,File.join('..',path)).map do |gem_path|
    File.expand_path(gem_path)
  end
end