Object
The Dependency class holds a Gem name and a Gem::Requirement.
Valid dependency types.
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 34 34: def initialize name, *requirements 35: if Regexp === name then 36: msg = ["NOTE: Dependency.new w/ a regexp is deprecated.", 37: "Dependency.new called from #{Gem.location_of_caller.join(":")}"] 38: warn msg.join("\n") unless Gem::Deprecate.skip 39: end 40: 41: type = Symbol === requirements.last ? requirements.pop : :runtime 42: requirements = requirements.first if 1 == requirements.length # unpack 43: 44: unless TYPES.include? type 45: raise ArgumentError, "Valid types are #{TYPES.inspect}, " 46: + "not #{type.inspect}" 47: end 48: 49: @name = name 50: @requirement = Gem::Requirement.create requirements 51: @type = type 52: @prerelease = false 53: 54: # This is for Marshal backwards compatibility. See the comments in 55: # +requirement+ for the dirty details. 56: 57: @version_requirements = @requirement 58: end
Dependencies are ordered by name.
# File lib/rubygems/dependency.rb, line 154 154: def <=> other 155: self.name <=> other.name 156: 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 164 164: def =~ other 165: unless Gem::Dependency === other 166: return unless other.respond_to?(:name) && other.respond_to?(:version) 167: other = Gem::Dependency.new other.name, other.version 168: end 169: 170: return false unless name === other.name 171: 172: reqs = other.requirement.requirements 173: 174: return false unless reqs.length == 1 175: return false unless reqs.first.first == '=' 176: 177: version = reqs.first.last 178: 179: requirement.satisfied_by? version 180: end
# File lib/rubygems/dependency.rb, line 182 182: def match? name, version 183: return false unless self.name === name 184: return true if requirement.none? 185: 186: requirement.satisfied_by? Gem::Version.new(version) 187: end
# File lib/rubygems/dependency.rb, line 189 189: def matches_spec? spec 190: return false unless name === spec.name 191: return true if requirement.none? 192: 193: requirement.satisfied_by?(spec.version) 194: end
# File lib/rubygems/dependency.rb, line 215 215: def matching_specs platform_only = false 216: matches = Gem::Specification.find_all { |spec| 217: self.name === spec.name and # TODO: == instead of === 218: requirement.satisfied_by? spec.version 219: } 220: 221: if platform_only 222: matches.reject! { |spec| 223: not Gem::Platform.match spec.platform 224: } 225: end 226: 227: matches = matches.sort_by { |s| s.sort_obj } # HACK: shouldn't be needed 228: end
Merges the requirements of other into this dependency
# File lib/rubygems/dependency.rb, line 199 199: def merge other 200: unless name == other.name then 201: raise ArgumentError, 202: "#{self} and #{other} have different names" 203: end 204: 205: default = Gem::Requirement.default 206: self_req = self.requirement 207: other_req = other.requirement 208: 209: return self.class.new name, self_req if other_req == default 210: return self.class.new name, other_req if self_req == default 211: 212: self.class.new name, self_req.as_list.concat(other_req.as_list) 213: end
Does this dependency require a prerelease?
# File lib/rubygems/dependency.rb, line 76 76: def prerelease? 77: @prerelease || requirement.prerelease? 78: end
What does this dependency require?
# File lib/rubygems/dependency.rb, line 98 98: def requirement 99: return @requirement if defined?(@requirement) and @requirement 100: 101: # @version_requirements and @version_requirement are legacy ivar 102: # names, and supported here because older gems need to keep 103: # working and Dependency doesn't implement marshal_dump and 104: # marshal_load. In a happier world, this would be an 105: # attr_accessor. The horrifying instance_variable_get you see 106: # below is also the legacy of some old restructurings. 107: # 108: # Note also that because of backwards compatibility (loading new 109: # gems in an old RubyGems installation), we can't add explicit 110: # marshaling to this class until we want to make a big 111: # break. Maybe 2.0. 112: # 113: # Children, define explicit marshal and unmarshal behavior for 114: # public classes. Marshal formats are part of your public API. 115: 116: if defined?(@version_requirement) && @version_requirement 117: version = @version_requirement.instance_variable_get :@version 118: @version_requirement = nil 119: @version_requirements = Gem::Requirement.new version 120: end 121: 122: @requirement = @version_requirements if defined?(@version_requirements) 123: end
# File lib/rubygems/dependency.rb, line 125 125: def requirements_list 126: requirement.as_list 127: end
True if the dependency will not always match the latest version.
# File lib/rubygems/dependency.rb, line 233 233: def specific? 234: @requirement.specific? 235: end
# File lib/rubygems/dependency.rb, line 255 255: def to_spec 256: matches = self.to_specs 257: 258: matches.find { |spec| spec.activated? } or matches.last 259: end
# File lib/rubygems/dependency.rb, line 237 237: def to_specs 238: matches = matching_specs true 239: 240: # TODO: check Gem.activated_spec[self.name] in case matches falls outside 241: 242: if matches.empty? then 243: specs = Gem::Specification.all_names.join ", " 244: error = Gem::LoadError.new "Could not find #{name} (#{requirement}) amongst [#{specs}]" 245: error.name = self.name 246: error.requirement = self.requirement 247: raise error 248: end 249: 250: # TODO: any other resolver validations should go here 251: 252: matches 253: end
Dependency type.
# File lib/rubygems/dependency.rb, line 140 140: def type 141: @type ||= :runtime 142: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.