Class: Pod::Vendor::Gem::Version
- Inherits:
-
Object
- Object
- Pod::Vendor::Gem::Version
- Includes:
- Comparable
- Defined in:
- lib/cocoapods-core/vendor/version.rb
Direct Known Subclasses
Constant Summary collapse
- VERSION_PATTERN =
:nodoc:
'[0-9]+(\.[0-9a-zA-Z]+)*'
- ANCHORED_VERSION_PATTERN =
:nodoc:
/\A\s*(#{VERSION_PATTERN})*\s*\z/
- Requirement =
::Gem::Version::Requirement = ::Gem::Requirement
Gem::Requirement
Instance Attribute Summary collapse
-
#version ⇒ Object
(also: #to_s)
readonly
A string representation of this Version.
Class Method Summary collapse
-
.correct?(version) ⇒ Boolean
True if the
version
string matches RubyGems’ requirements. -
.create(input) ⇒ Object
Factory method to create a Version object.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compares this version with
other
returning -1, 0, or 1 if the other version is larger, the same, or smaller than this one. -
#bump ⇒ Object
Return a new version object where the next to the last revision number is one greater (e.g., 5.3.1 => 5.4).
-
#eql?(other) ⇒ Boolean
A Version is only eql? to another version if it’s specified to the same precision.
-
#hash ⇒ Object
:nodoc:.
-
#init_with(coder) ⇒ Object
:nodoc:.
-
#initialize(version) ⇒ Version
constructor
Constructs a Version from the
version
string. -
#inspect ⇒ Object
:nodoc:.
-
#marshal_dump ⇒ Object
Dump only the raw version string, not the complete object.
-
#marshal_load(array) ⇒ Object
Load custom marshal format.
-
#optimistic_recommendation ⇒ Object
A recommended version for use with a ~> Requirement.
-
#prerelease? ⇒ Boolean
A version is considered a prerelease if it contains a letter.
-
#pretty_print(q) ⇒ Object
:nodoc:.
-
#release ⇒ Object
The release for this version (e.g. 1.2.0.a -> 1.2.0).
-
#segments ⇒ Object
:nodoc:.
- #yaml_initialize(tag, map) ⇒ Object
Constructor Details
#initialize(version) ⇒ Version
Constructs a Version from the version
string. A version string is a series of digits or ASCII letters separated by dots.
189 190 191 192 193 194 195 196 |
# File 'lib/cocoapods-core/vendor/version.rb', line 189 def initialize(version) unless self.class.correct?(version) raise ArgumentError, "Malformed version number string #{version}" end @version = version.to_s @version.strip! end |
Instance Attribute Details
#version ⇒ Object (readonly) Also known as: to_s
A string representation of this Version.
157 158 159 |
# File 'lib/cocoapods-core/vendor/version.rb', line 157 def version @version end |
Class Method Details
.correct?(version) ⇒ Boolean
True if the version
string matches RubyGems’ requirements.
163 164 165 |
# File 'lib/cocoapods-core/vendor/version.rb', line 163 def self.correct?(version) version.to_s =~ ANCHORED_VERSION_PATTERN end |
.create(input) ⇒ Object
175 176 177 178 179 180 181 182 183 |
# File 'lib/cocoapods-core/vendor/version.rb', line 175 def self.create(input) if input.respond_to? :version then input elsif input.nil? then nil else new input end end |
Instance Method Details
#<=>(other) ⇒ Object
Compares this version with other
returning -1, 0, or 1 if the other version is larger, the same, or smaller than this one. Attempts to compare to something that’s not a Gem::Version
return nil
.
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/cocoapods-core/vendor/version.rb', line 307 def <=>(other) return unless Gem::Version === other return 0 if @version == other.version lhsegments = segments rhsegments = other.segments lhsize = lhsegments.size rhsize = rhsegments.size limit = (lhsize > rhsize ? lhsize : rhsize) - 1 i = 0 while i <= limit lhs, rhs = lhsegments[i] || 0, rhsegments[i] || 0 i += 1 next if lhs == rhs return -1 if String === lhs && Numeric === rhs return 1 if Numeric === lhs && String === rhs return lhs <=> rhs end 0 end |
#bump ⇒ Object
Return a new version object where the next to the last revision number is one greater (e.g., 5.3.1 => 5.4).
Pre-release (alpha) parts, e.g, 5.3.1.b.2 => 5.4, are ignored.
204 205 206 207 208 209 210 211 |
# File 'lib/cocoapods-core/vendor/version.rb', line 204 def bump segments = self.segments.dup segments.pop while segments.any? { |s| String === s } segments.pop if segments.size > 1 segments[-1] = segments[-1].succ self.class.new segments.join(".") end |
#eql?(other) ⇒ Boolean
A Version is only eql? to another version if it’s specified to the same precision. Version “1.0” is not the same as version “1”.
217 218 219 |
# File 'lib/cocoapods-core/vendor/version.rb', line 217 def eql?(other) self.class === other and @version == other.version end |
#hash ⇒ Object
:nodoc:
221 222 223 |
# File 'lib/cocoapods-core/vendor/version.rb', line 221 def hash # :nodoc: @hash ||= segments.hash end |
#init_with(coder) ⇒ Object
:nodoc:
225 226 227 |
# File 'lib/cocoapods-core/vendor/version.rb', line 225 def init_with(coder) # :nodoc: yaml_initialize coder.tag, coder.map end |
#inspect ⇒ Object
:nodoc:
229 230 231 |
# File 'lib/cocoapods-core/vendor/version.rb', line 229 def inspect # :nodoc: "#<#{self.class} #{version.inspect}>" end |
#marshal_dump ⇒ Object
Dump only the raw version string, not the complete object. It’s a string for backwards (RubyGems 1.3.5 and earlier) compatibility.
237 238 239 |
# File 'lib/cocoapods-core/vendor/version.rb', line 237 def marshal_dump [version] end |
#marshal_load(array) ⇒ Object
Load custom marshal format. It’s a string for backwards (RubyGems 1.3.5 and earlier) compatibility.
245 246 247 |
# File 'lib/cocoapods-core/vendor/version.rb', line 245 def marshal_load(array) initialize array[0] end |
#optimistic_recommendation ⇒ Object
A recommended version for use with a ~> Requirement.
291 292 293 294 295 296 297 298 299 |
# File 'lib/cocoapods-core/vendor/version.rb', line 291 def optimistic_recommendation segments = self.segments.dup segments.pop while segments.any? { |s| String === s } segments.pop while segments.size > 2 segments.push 0 while segments.size < 2 "~> #{segments.join(".")}" end |
#prerelease? ⇒ Boolean
A version is considered a prerelease if it contains a letter.
258 259 260 |
# File 'lib/cocoapods-core/vendor/version.rb', line 258 def prerelease? @prerelease ||= @version =~ /[a-zA-Z]/ end |
#pretty_print(q) ⇒ Object
:nodoc:
262 263 264 |
# File 'lib/cocoapods-core/vendor/version.rb', line 262 def pretty_print(q) # :nodoc: q.text "Gem::Version.new(#{version.inspect})" end |
#release ⇒ Object
The release for this version (e.g. 1.2.0.a -> 1.2.0). Non-prerelease versions return themselves.
270 271 272 273 274 275 276 |
# File 'lib/cocoapods-core/vendor/version.rb', line 270 def release return self unless prerelease? segments = self.segments.dup segments.pop while segments.any? { |s| String === s } self.class.new segments.join('.') end |
#segments ⇒ Object
:nodoc:
278 279 280 281 282 283 284 285 286 |
# File 'lib/cocoapods-core/vendor/version.rb', line 278 def segments # :nodoc: # segments is lazy so it can pick up version values that come from # old marshaled versions, which don't go through marshal_load. @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s| /^\d+$/ =~ s ? s.to_i : s end end |
#yaml_initialize(tag, map) ⇒ Object
249 250 251 252 253 |
# File 'lib/cocoapods-core/vendor/version.rb', line 249 def yaml_initialize(tag, map) @version = map['version'] @segments = nil @hash = nil end |