Class: Gem::Dependency
Overview
The Dependency class holds a Gem name and a Gem::Requirement.
Constant Summary
- TYPES =
Valid dependency types. -- When this list is updated, be sure to change Gem::Specification::CURRENT_SPECIFICATION_VERSION as well.
[ :development, :runtime, ]
Instance Attribute Summary (collapse)
-
- (Object) name
Dependency name or regular expression.
-
- (Object) prerelease
writeonly
Allows you to force this dependency to be a prerelease.
-
- (Object) type
readonly
Dependency type.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (Object) <=>(other)
Dependencies are ordered by name.
-
- (Object) ==(other)
:nodoc:.
-
- (Object) =~(other)
Uses this dependency as a pattern to compare to other.
-
- (Object) hash
A dependency's hash is the XOR of the hashes of name, type, and requirement.
-
- (Dependency) initialize(name, *requirements)
constructor
Constructs a dependency with name and requirements.
-
- (Object) inspect
:nodoc:.
- - (Boolean) match?(name, version)
- - (Boolean) matches_spec?(spec)
-
- (Boolean) prerelease?
Does this dependency require a prerelease?.
-
- (Object) pretty_print(q)
:nodoc:.
-
- (Object) requirement
(also: #__requirement)
What does this dependency require?.
-
- (Object) requirements_list
:nodoc:.
-
- (Object) to_s
:nodoc:.
-
- (Object) version_requirements
(also: #version_requirement)
:nodoc:.
-
- (Object) version_requirements=(requirements)
:nodoc:.
Constructor Details
- (Dependency) initialize(name, *requirements)
Constructs a dependency with name and requirements. The last argument can optionally be the dependency type, which defaults to :runtime.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rubygems/dependency.rb', line 51 def initialize name, *requirements type = Symbol === requirements.last ? requirements.pop : :runtime requirements = requirements.first if 1 == requirements.length # unpack unless TYPES.include? type raise ArgumentError, "Valid types are #{TYPES.inspect}, " + "not #{type.inspect}" end @name = name @requirement = Gem::Requirement.create requirements @type = type @prerelease = false # This is for Marshal backwards compatability. See the comments in # +requirement+ for the dirty details. @version_requirements = @requirement end |
Instance Attribute Details
- (Object) name
Dependency name or regular expression.
34 35 36 |
# File 'lib/rubygems/dependency.rb', line 34 def name @name end |
- (Object) prerelease=(value) (writeonly)
Allows you to force this dependency to be a prerelease.
39 40 41 |
# File 'lib/rubygems/dependency.rb', line 39 def prerelease=(value) @prerelease = value end |
- (Object) type (readonly)
Dependency type.
44 45 46 |
# File 'lib/rubygems/dependency.rb', line 44 def type @type end |
Class Method Details
+ (Object) warned_version_requirement
11 12 13 |
# File 'lib/rubygems/dependency.rb', line 11 def self.warned_version_requirement @warned_version_requirement end |
+ (Object) warned_version_requirement=(value)
15 16 17 |
# File 'lib/rubygems/dependency.rb', line 15 def self.warned_version_requirement= value @warned_version_requirement = value end |
Instance Method Details
- (Object) <=>(other)
Dependencies are ordered by name.
184 185 186 |
# File 'lib/rubygems/dependency.rb', line 184 def <=> other @name <=> other.name end |
- (Object) ==(other)
:nodoc:
174 175 176 177 178 179 |
# File 'lib/rubygems/dependency.rb', line 174 def == other # :nodoc: Gem::Dependency === other && self.name == other.name && self.type == other.type && self.requirement == other.requirement end |
- (Object) =~(other)
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.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/rubygems/dependency.rb', line 194 def =~ other unless Gem::Dependency === other return unless other.respond_to?(:name) && other.respond_to?(:version) other = Gem::Dependency.new other.name, other.version end return false unless name === other.name reqs = other.requirement.requirements return false unless reqs.length == 1 return false unless reqs.first.first == '=' version = reqs.first.last requirement.satisfied_by? version end |
- (Object) hash
A dependency's hash is the XOR of the hashes of name, type, and requirement.
75 76 77 |
# File 'lib/rubygems/dependency.rb', line 75 def hash # :nodoc: name.hash ^ type.hash ^ requirement.hash end |
- (Object) inspect
:nodoc:
79 80 81 82 |
# File 'lib/rubygems/dependency.rb', line 79 def inspect # :nodoc: "<%s type=%p name=%p requirements=%p>" % [self.class, @type, @name, requirement.to_s] end |
- (Boolean) match?(name, version)
212 213 214 215 216 217 |
# File 'lib/rubygems/dependency.rb', line 212 def match? name, version return false unless self.name === name return true if requirement.none? requirement.satisfied_by? Gem::Version.new(version) end |
- (Boolean) matches_spec?(spec)
219 220 221 222 223 224 |
# File 'lib/rubygems/dependency.rb', line 219 def matches_spec? spec return false unless name === spec.name return true if requirement.none? requirement.satisfied_by?(spec.version) end |
- (Boolean) prerelease?
Does this dependency require a prerelease?
87 88 89 |
# File 'lib/rubygems/dependency.rb', line 87 def prerelease? @prerelease || requirement.prerelease? end |
- (Object) pretty_print(q)
:nodoc:
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rubygems/dependency.rb', line 91 def pretty_print q # :nodoc: q.group 1, 'Gem::Dependency.new(', ')' do q.pp name q.text ',' q.breakable q.pp requirement q.text ',' q.breakable q.pp type end end |
- (Object) requirement Also known as: __requirement
What does this dependency require?
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/rubygems/dependency.rb', line 109 def requirement return @requirement if defined?(@requirement) and @requirement # @version_requirements and @version_requirement are legacy ivar # names, and supported here because older gems need to keep # working and Dependency doesn't implement marshal_dump and # marshal_load. In a happier world, this would be an # attr_accessor. The horrifying instance_variable_get you see # below is also the legacy of some old restructurings. # # Note also that because of backwards compatibility (loading new # gems in an old RubyGems installation), we can't add explicit # marshaling to this class until we want to make a big # break. Maybe 2.0. # # Children, define explicit marshal and unmarshal behavior for # public classes. Marshal formats are part of your public API. if defined?(@version_requirement) && @version_requirement version = @version_requirement.instance_variable_get :@version @version_requirement = nil @version_requirements = Gem::Requirement.new version end @requirement = @version_requirements if defined?(@version_requirements) end |
- (Object) requirements_list
:nodoc:
142 143 144 |
# File 'lib/rubygems/dependency.rb', line 142 def requirements_list requirement.as_list end |
- (Object) to_s
:nodoc:
146 147 148 |
# File 'lib/rubygems/dependency.rb', line 146 def to_s # :nodoc: "#{name} (#{requirement}, #{type})" end |
- (Object) version_requirements Also known as: version_requirement
:nodoc:
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/rubygems/dependency.rb', line 150 def version_requirements # :nodoc: unless Gem::Dependency.warned_version_requirement then warn "#{Gem.location_of_caller.join ':'}:Warning: " \ "Gem::Dependency#version_requirements is deprecated " \ "and will be removed on or after August 2010. " \ "Use #requirement" Gem::Dependency.warned_version_requirement = true end __requirement end |
- (Object) version_requirements=(requirements)
:nodoc:
165 166 167 168 169 170 171 172 |
# File 'lib/rubygems/dependency.rb', line 165 def version_requirements= requirements # :nodoc: warn "#{Gem.location_of_caller.join ':'}:Warning: " \ "Gem::Dependency#version_requirements= is deprecated " \ "and will be removed on or after August 2010. " \ "Use Gem::Dependency.new." @requirement = Gem::Requirement.create requirements end |