Class: Pod::Version

Inherits:
Pod::Vendor::Gem::Version show all
Defined in:
lib/cocoapods-core/version.rb

Overview

The Version class stores information about the version of a Specification.

It is based on the RubyGems class adapted to support head information.

From RubyGems:

The Version class processes string versions into comparable values. A version string should normally be a series of numbers separated by periods. Each part (digits separated by periods) is considered its own number, and these are used for sorting. So for instance, 3.10 sorts higher than 3.2 because ten is greater than two.

If any part contains letters (currently only a-z are supported) then that version is considered prerelease. Versions with a prerelease part in the Nth part sort less than versions with N-1 parts. Prerelease parts are sorted alphabetically using the normal Ruby string sorting rules. If a prerelease part contains both letters and numbers, it will be broken into multiple parts to provide expected sort behavior (1.0.a10 becomes 1.0.a.10, and is greater than 1.0.a9).

Prereleases sort between real releases (newest to oldest):

  1. 1.0
  2. 1.0.b1
  3. 1.0.a.2
  4. 0.9

Semantic Versioning collapse

SEMVER_PATTERN =
'[0-9]+(\.[0-9]+(\.[0-9]+(-[0-9A-Za-z\-\.]+)?)?)?'
ANCHORED_SEMANTIC_VERSION_PATTERN =
/\A\s*(#{SEMVER_PATTERN})*\s*\z/

Constant Summary collapse

VERSION_PATTERN =

Override the constants defined by the superclass to add Semantic Versioning prerelease support (with a dash). E.g.: 1.0.0-alpha1

For more info, see: http://semver.org

'[0-9]+(\.[0-9a-zA-Z\-]+)*'
ANCHORED_VERSION_PATTERN =
/\A\s*(#{VERSION_PATTERN})*\s*\z/
ZERO =

An instance that represents version 0.

new('0')

Constants inherited from Pod::Vendor::Gem::Version

Pod::Vendor::Gem::Version::Requirement

Instance Attribute Summary collapse

Semantic Versioning collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pod::Vendor::Gem::Version

#<=>, #approximate_recommendation, #bump, create, #encode_with, #eql?, #hash, #init_with, #marshal_dump, #marshal_load, new, #pretty_print, #release, #segments, #to_yaml_properties, #version, #yaml_initialize

Constructor Details

#initialize(version) ⇒ Version

TODO:

The from part of the regular expression should be remove in CocoaPods 1.0.0.

Returns a new instance of Version

Parameters:

  • version (String, Version)

    A string representing a version, or another version.

Raises:

  • (ArgumentError)

52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cocoapods-core/version.rb', line 52

def initialize(version)
  if version.is_a?(Version) && version.head?
    version = version.version
    @head = true
  elsif version.is_a?(String) && version =~ /HEAD (based on|from) (.*)/
    version = Regexp.last_match[2]
    @head = true
  end

  raise ArgumentError, "Malformed version number string #{version}" unless
    self.class.correct?(version)

  @version = version.to_s.strip
end

Instance Attribute Details

#headBool Also known as: head?

Returns whether the version represents the head of repository.

Returns:

  • (Bool)

    whether the version represents the head of repository.


43
44
45
# File 'lib/cocoapods-core/version.rb', line 43

def head
  @head
end

Class Method Details

.correct?(version) ⇒ Bool

Returns Whether a string representation is correct.

Returns:

  • (Bool)

    Whether a string representation is correct.


103
104
105
# File 'lib/cocoapods-core/version.rb', line 103

def self.correct?(version)
  version.to_s =~ ANCHORED_VERSION_PATTERN
end

Instance Method Details

#inspectString

Returns a string representation suitable for debugging.

Returns:

  • (String)

    a string representation suitable for debugging.


86
87
88
# File 'lib/cocoapods-core/version.rb', line 86

def inspect
  "<#{self.class} version=#{version}>"
end

#majorFixnum

Returns The semver major identifier.

Returns:

  • (Fixnum)

    The semver major identifier.


127
128
129
# File 'lib/cocoapods-core/version.rb', line 127

def major
  segments[0]
end

#minorFixnum

Returns The semver minor identifier.

Returns:

  • (Fixnum)

    The semver minor identifier.


133
134
135
# File 'lib/cocoapods-core/version.rb', line 133

def minor
  segments[1] || 0
end

#patchFixnum

Returns The semver patch identifier.

Returns:

  • (Fixnum)

    The semver patch identifier.


139
140
141
# File 'lib/cocoapods-core/version.rb', line 139

def patch
  segments[2] || 0
end

#prerelease?Boolean

Note:

Prerelease Pods can contain a hyphen and/or a letter (conforms to Semantic Versioning instead of RubyGems).

For more info, see: http://semver.org

Returns indicates whether or not the version is a prerelease.

Returns:

  • (Boolean)

    indicates whether or not the version is a prerelease.


97
98
99
# File 'lib/cocoapods-core/version.rb', line 97

def prerelease?
  @prerelease ||= @version =~ /[a-zA-Z\-]/
end

#semantic?Bool

Note:

This comparison is lenient.

Note:

It doesn't support build identifiers.

Returns Whether the version conforms to the Semantic Versioning specification (2.0.0-rc.1).

Returns:

  • (Bool)

    Whether the version conforms to the Semantic Versioning specification (2.0.0-rc.1).


121
122
123
# File 'lib/cocoapods-core/version.rb', line 121

def semantic?
  version.to_s =~ ANCHORED_SEMANTIC_VERSION_PATTERN
end

#to_sString

TODO:

Adding the head information to the string representation creates issues (see Dependency#requirement).

Note:

The raw version string is still accessible with the Pod::Vendor::Gem::Version#version method.

Returns a string representation that indicates if the version is head.

Returns:

  • (String)

    a string representation that indicates if the version is head.


80
81
82
# File 'lib/cocoapods-core/version.rb', line 80

def to_s
  head? ? "HEAD based on #{super}" : super
end