| Class | Gem::Dependency |
| In: |
lib/rubygems/dependency.rb
|
| Parent: | Object |
The Dependency class holds a Gem name and a Gem::Requirement.
| TYPES | = | [ :development, :runtime, ] | Valid dependency types. |
| version_requirements | -> | version_requirement |
| name | [RW] | Dependency name or regular expression. |
| prerelease | [W] | Allows you to force this dependency to be a prerelease. |
| type | [R] | Dependency type. |
Constructs a dependency with name and requirements. The last argument can optionally be the dependency type, which defaults to :runtime.
# File lib/rubygems/dependency.rb, line 51
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
Dependencies are ordered by name.
# File lib/rubygems/dependency.rb, line 184
184: def <=> other
185: [@name] <=> [other.name]
186: end
Uses this dependency as a pattern to compare to other. This dependency will match if the name matches the other‘s name, and other has only an equal version requirement that satisfies this dependency.
# File lib/rubygems/dependency.rb, line 194
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
# File lib/rubygems/dependency.rb, line 217
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
Does this dependency require a prerelease?
# File lib/rubygems/dependency.rb, line 87
87: def prerelease?
88: @prerelease || requirement.prerelease?
89: end
What does this dependency require?
# File lib/rubygems/dependency.rb, line 109
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