Parent

Class Index [+]

Quicksearch

Gem::Dependency

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

Constants

TYPES

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

new(name, *requirements) click to toggle source

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

Public Instance Methods

<=>(other) click to toggle source

Dependencies are ordered by name.

     # File lib/rubygems/dependency.rb, line 184
184:   def <=> other
185:     [@name] <=> [other.name]
186:   end
=~(other) click to toggle source

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
__requirement() click to toggle source

Rails subclasses Gem::Dependency and uses this method, so we’ll hack around it.

Alias for: requirement
match?(spec_name, spec_version) click to toggle source
     # 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
prerelease?() click to toggle source

Does this dependency require a prerelease?

    # File lib/rubygems/dependency.rb, line 87
87:   def prerelease?
88:     @prerelease || requirement.prerelease?
89:   end
requirement() click to toggle source

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
Also aliased as: __requirement
requirements_list() click to toggle source
     # File lib/rubygems/dependency.rb, line 142
142:   def requirements_list
143:     requirement.as_list
144:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.