Geminstaller C0 Coverage Information - RCov

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

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/dependency.rb 232 120
68.53%
49.17%

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 require "rubygems/requirement"
2 
3 ##
4 # The Dependency class holds a Gem name and a Gem::Requirement.
5 
6 class Gem::Dependency
7 
8   # :stopdoc:
9   @warned_version_requirement = false
10 
11   def self.warned_version_requirement
12     @warned_version_requirement
13   end
14 
15   def self.warned_version_requirement= value
16     @warned_version_requirement = value
17   end
18   # :startdoc:
19 
20   ##
21   # Valid dependency types.
22   #--
23   # When this list is updated, be sure to change
24   # Gem::Specification::CURRENT_SPECIFICATION_VERSION as well.
25 
26   TYPES = [
27            :development,
28            :runtime,
29           ]
30 
31   ##
32   # Dependency name or regular expression.
33 
34   attr_accessor :name
35 
36   ##
37   # Allows you to force this dependency to be a prerelease.
38 
39   attr_writer :prerelease
40 
41   ##
42   # Dependency type.
43 
44   attr_reader :type
45 
46   ##
47   # Constructs a dependency with +name+ and +requirements+. The last
48   # argument can optionally be the dependency type, which defaults to
49   # <tt>:runtime</tt>.
50 
51   def initialize name, *requirements
52     type         = Symbol === requirements.last ? requirements.pop : :runtime
53     requirements = requirements.first if 1 == requirements.length # unpack
54 
55     unless TYPES.include? type
56       raise ArgumentError, "Valid types are #{TYPES.inspect}, "
57         + "not #{@type.inspect}"
58     end
59 
60     @name        = name
61     @requirement = Gem::Requirement.create requirements
62     @type        = type
63     @prerelease  = false
64 
65     # This is for Marshal backwards compatability. See the comments in
66     # +requirement+ for the dirty details.
67 
68     @version_requirements = @requirement
69   end
70 
71   ##
72   # A dependency's hash is the XOR of the hashes of +name+, +type+,
73   # and +requirement+.
74 
75   def hash # :nodoc:
76     name.hash ^ type.hash ^ requirement.hash
77   end
78 
79   def inspect # :nodoc:
80     "<%s type=%p name=%p requirements=%p>" %
81       [self.class, @type, @name, requirement.to_s]
82   end
83 
84   ##
85   # Does this dependency require a prerelease?
86 
87   def prerelease?
88     @prerelease || requirement.prerelease?
89   end
90 
91   def pretty_print(q) # :nodoc:
92     q.group 1, 'Gem::Dependency.new(', ')' do
93       q.pp name
94       q.text ','
95       q.breakable
96 
97       q.pp requirement
98 
99       q.text ','
100       q.breakable
101 
102       q.pp type
103     end
104   end
105 
106   ##
107   # What does this dependency require?
108 
109   def requirement
110     return @requirement if defined?(@requirement) and @requirement
111 
112     # @version_requirements and @version_requirement are legacy ivar
113     # names, and supported here because older gems need to keep
114     # working and Dependency doesn't implement marshal_dump and
115     # marshal_load. In a happier world, this would be an
116     # attr_accessor. The horrifying instance_variable_get you see
117     # below is also the legacy of some old restructurings.
118     #
119     # Note also that because of backwards compatibility (loading new
120     # gems in an old RubyGems installation), we can't add explicit
121     # marshaling to this class until we want to make a big
122     # break. Maybe 2.0.
123     #
124     # Children, define explicit marshal and unmarshal behavior for
125     # public classes. Marshal formats are part of your public API.
126 
127     if defined?(@version_requirement) && @version_requirement
128       version = @version_requirement.instance_variable_get :@version
129       @version_requirement  = nil
130       @version_requirements = Gem::Requirement.new version
131     end
132 
133     @requirement = @version_requirements if defined?(@version_requirements)
134   end
135 
136   ##
137   # Rails subclasses Gem::Dependency and uses this method, so we'll hack
138   # around it.
139 
140   alias __requirement requirement # :nodoc:
141 
142   def requirements_list
143     requirement.as_list
144   end
145 
146   def to_s # :nodoc:
147     "#{name} (#{requirement}, #{type})"
148   end
149 
150   def version_requirements # :nodoc:
151     unless Gem::Dependency.warned_version_requirement then
152       warn "#{Gem.location_of_caller.join ':'}:Warning: " \
153            "Gem::Dependency#version_requirements is deprecated " \
154            "and will be removed on or after August 2010.  " \
155            "Use #requirement"
156 
157       Gem::Dependency.warned_version_requirement = true
158     end
159 
160     __requirement
161   end
162 
163   alias version_requirement version_requirements # :nodoc:
164 
165   def version_requirements= requirements # :nodoc:
166     warn "#{Gem.location_of_caller.join ':'}:Warning: " \
167          "Gem::Dependency#version_requirements= is deprecated " \
168          "and will be removed on or after August 2010.  " \
169          "Use Gem::Dependency.new."
170 
171     @requirement = Gem::Requirement.create requirements
172   end
173 
174   def == other # :nodoc:
175     Gem::Dependency === other &&
176       self.name        == other.name &&
177       self.type        == other.type &&
178       self.requirement == other.requirement
179   end
180 
181   ##
182   # Dependencies are ordered by name.
183 
184   def <=> other
185     [@name] <=> [other.name]
186   end
187 
188   ##
189   # Uses this dependency as a pattern to compare to +other+. This
190   # dependency will match if the name matches the other's name, and
191   # other has only an equal version requirement that satisfies this
192   # dependency.
193 
194   def =~ other
195     unless Gem::Dependency === other
196       other = Gem::Dependency.new other.name, other.version rescue return false
197     end
198 
199     pattern = name
200 
201     if Regexp === pattern then
202       return false unless pattern =~ other.name
203     else
204       return false unless pattern == other.name
205     end
206 
207     reqs = other.requirement.requirements
208 
209     return false unless reqs.length == 1
210     return false unless reqs.first.first == '='
211 
212     version = reqs.first.last
213 
214     requirement.satisfied_by? version
215   end
216 
217   def match?(spec_name, spec_version)
218     pattern = name
219 
220     if Regexp === pattern
221       return false unless pattern =~ spec_name
222     else
223       return false unless pattern == spec_name
224     end
225 
226     return true if requirement.none?
227 
228     requirement.satisfied_by? Gem::Version.new(spec_version)
229   end
230 
231 end
232 

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