Class Gem::Dependency
In: lib/rubygems/dependency.rb
Parent: Object

The Dependency class holds a Gem name and a Gem::Requirement.

Methods

Constants

TYPES = [ :development, :runtime, ]   Valid dependency types.

Attributes

name  [RW]  Dependency name or regular expression.
prerelease  [W]  Allows you to force this dependency to be a prerelease.
type  [R]  Dependency type.

Public Class methods

Constructs a dependency with name and requirements. The last argument can optionally be the dependency type, which defaults to :runtime.

[Source]

    # File lib/rubygems/dependency.rb, line 39
39:   def initialize name, *requirements
40:     type         = Symbol === requirements.last ? requirements.pop : :runtime
41:     requirements = requirements.first if 1 == requirements.length # unpack
42: 
43:     unless TYPES.include? type
44:       raise ArgumentError, "Valid types are #{TYPES.inspect}, "
45:         + "not #{type.inspect}"
46:     end
47: 
48:     @name        = name
49:     @requirement = Gem::Requirement.create requirements
50:     @type        = type
51:     @prerelease  = false
52: 
53:     # This is for Marshal backwards compatibility. See the comments in
54:     # +requirement+ for the dirty details.
55: 
56:     @version_requirements = @requirement
57:   end

Public Instance methods

Dependencies are ordered by name.

[Source]

     # File lib/rubygems/dependency.rb, line 142
142:   def <=> other
143:     @name <=> other.name
144:   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.

[Source]

     # File lib/rubygems/dependency.rb, line 152
152:   def =~ other
153:     unless Gem::Dependency === other
154:       return unless other.respond_to?(:name) && other.respond_to?(:version)
155:       other = Gem::Dependency.new other.name, other.version
156:     end
157: 
158:     return false unless name === other.name
159: 
160:     reqs = other.requirement.requirements
161: 
162:     return false unless reqs.length == 1
163:     return false unless reqs.first.first == '='
164: 
165:     version = reqs.first.last
166: 
167:     requirement.satisfied_by? version
168:   end

[Source]

     # File lib/rubygems/dependency.rb, line 170
170:   def match? name, version
171:     return false unless self.name === name
172:     return true if requirement.none?
173: 
174:     requirement.satisfied_by? Gem::Version.new(version)
175:   end

[Source]

     # File lib/rubygems/dependency.rb, line 177
177:   def matches_spec? spec
178:     return false unless name === spec.name
179:     return true  if requirement.none?
180: 
181:     requirement.satisfied_by?(spec.version)
182:   end

Does this dependency require a prerelease?

[Source]

    # File lib/rubygems/dependency.rb, line 75
75:   def prerelease?
76:     @prerelease || requirement.prerelease?
77:   end

What does this dependency require?

[Source]

     # File lib/rubygems/dependency.rb, line 97
 97:   def requirement
 98:     return @requirement if defined?(@requirement) and @requirement
 99: 
100:     # @version_requirements and @version_requirement are legacy ivar
101:     # names, and supported here because older gems need to keep
102:     # working and Dependency doesn't implement marshal_dump and
103:     # marshal_load. In a happier world, this would be an
104:     # attr_accessor. The horrifying instance_variable_get you see
105:     # below is also the legacy of some old restructurings.
106:     #
107:     # Note also that because of backwards compatibility (loading new
108:     # gems in an old RubyGems installation), we can't add explicit
109:     # marshaling to this class until we want to make a big
110:     # break. Maybe 2.0.
111:     #
112:     # Children, define explicit marshal and unmarshal behavior for
113:     # public classes. Marshal formats are part of your public API.
114: 
115:     if defined?(@version_requirement) && @version_requirement
116:       version = @version_requirement.instance_variable_get :@version
117:       @version_requirement  = nil
118:       @version_requirements = Gem::Requirement.new version
119:     end
120: 
121:     @requirement = @version_requirements if defined?(@version_requirements)
122:   end

[Source]

     # File lib/rubygems/dependency.rb, line 124
124:   def requirements_list
125:     requirement.as_list
126:   end

[Validate]