Geminstaller C0 Coverage Information - RCov

spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/gem_path_searcher.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/gem_path_searcher.rb 100 37
100.00%
100.00%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 ##
2 # GemPathSearcher has the capability to find loadable files inside
3 # gems.  It generates data up front to speed up searches later.
4 
5 class Gem::GemPathSearcher
6 
7   ##
8   # Initialise the data we need to make searches later.
9 
10   def initialize
11     # We want a record of all the installed gemspecs, in the order we wish to
12     # examine them.
13     @gemspecs = init_gemspecs
14 
15     # Map gem spec to glob of full require_path directories.  Preparing this
16     # information may speed up searches later.
17     @lib_dirs = {}
18 
19     @gemspecs.each do |spec|
20       @lib_dirs[spec.object_id] = lib_dirs_for spec
21     end
22   end
23 
24   ##
25   # Look in all the installed gems until a matching _path_ is found.
26   # Return the _gemspec_ of the gem where it was found.  If no match
27   # is found, return nil.
28   #
29   # The gems are searched in alphabetical order, and in reverse
30   # version order.
31   #
32   # For example:
33   #
34   #   find('log4r')              # -> (log4r-1.1 spec)
35   #   find('log4r.rb')           # -> (log4r-1.1 spec)
36   #   find('rake/rdoctask')      # -> (rake-0.4.12 spec)
37   #   find('foobarbaz')          # -> nil
38   #
39   # Matching paths can have various suffixes ('.rb', '.so', and
40   # others), which may or may not already be attached to _file_.
41   # This method doesn't care about the full filename that matches;
42   # only that there is a match.
43 
44   def find(path)
45     @gemspecs.find do |spec| matching_file? spec, path end
46   end
47 
48   ##
49   # Works like #find, but finds all gemspecs matching +path+.
50 
51   def find_all(path)
52     @gemspecs.select do |spec|
53       matching_file? spec, path
54     end
55   end
56 
57   ##
58   # Attempts to find a matching path using the require_paths of the given
59   # +spec+.
60 
61   def matching_file?(spec, path)
62     !matching_files(spec, path).empty?
63   end
64 
65   ##
66   # Returns files matching +path+ in +spec+.
67   #--
68   # Some of the intermediate results are cached in @lib_dirs for speed.
69 
70   def matching_files(spec, path)
71     return [] unless @lib_dirs[spec.object_id] # case no paths
72     glob = File.join @lib_dirs[spec.object_id], "#{path}#{Gem.suffix_pattern}"
73     Dir[glob].select { |f| File.file? f.untaint }
74   end
75 
76   ##
77   # Return a list of all installed gemspecs, sorted by alphabetical order and
78   # in reverse version order.  (bar-2, bar-1, foo-2)
79 
80   def init_gemspecs
81     specs = Gem.source_index.map { |_, spec| spec }
82 
83     specs.sort { |a, b|
84       names = a.name <=> b.name
85       next names if names.nonzero?
86       b.version <=> a.version
87     }
88   end
89 
90   ##
91   # Returns library directories glob for a gemspec.  For example,
92   #   '/usr/local/lib/ruby/gems/1.8/gems/foobar-1.0/{lib,ext}'
93 
94   def lib_dirs_for(spec)
95     "#{spec.full_gem_path}/{#{spec.require_paths.join(',')}}" if
96       spec.require_paths
97   end
98 
99 end
100 

Generated on Mon May 10 23:40:28 -0700 2010 with rcov 0.9.8