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\\-\\.]+)?#{METADATA_PATTERN}?)?)?"
ANCHORED_SEMANTIC_VERSION_PATTERN =
/\A\s*(#{SEMVER_PATTERN})*\s*\z/

Constant Summary collapse

METADATA_PATTERN =

Override the constants defined by the superclass to add:

  • Semantic Versioning prerelease support (with a dash). E.g.: 1.0.0-alpha1

  • Semantic Versioning metadata support (with a ) E.g: 1.0.096ef7ed

For more info, see: semver.org

'(\+[0-9a-zA-Z\-\.]+)'
VERSION_PATTERN =
"[0-9]+(\\.[0-9a-zA-Z\\-]+)*#{METADATA_PATTERN}?"
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

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

Returns a new instance of Version.

Parameters:

  • version (String, Version)

    A string representing a version, or another version.

Raises:

  • (ArgumentError)


46
47
48
49
50
51
# File 'lib/cocoapods-core/version.rb', line 46

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

  @version = version.to_s.strip
end

Class Method Details

.correct?(version) ⇒ Boolean

Returns Whether a string representation is correct.

Returns:

  • (Boolean)

    Whether a string representation is correct.



78
79
80
# File 'lib/cocoapods-core/version.rb', line 78

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

Instance Method Details

#<=(other) ⇒ Boolean

Note:

Attempts to compare something that’s not a Pod::Version return nil

Compares the versions for equality.

Parameters:

  • other (Version)

    The other version to compare.

Returns:

  • (Boolean)

    whether the receiver is less than or equal to other.



175
176
177
178
# File 'lib/cocoapods-core/version.rb', line 175

def <=(other)
  comparison = compare_segments(other)
  comparison <= 0
end

#<=>(other) ⇒ Fixnum

Note:

Attempts to compare something that’s not a Pod::Version return nil

Compares the versions for sorting.

Parameters:

  • other (Version)

    The other version to compare.

Returns:

  • (Fixnum)

    -1, 0, or +1 depending on whether the receiver is less than, equal to, or greater than other.



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

def <=>(other)
  comparison = compare_segments(other)
  comparison == 0 ? version <=> other.version : comparison
end

#==(other) ⇒ Boolean

Note:

Attempts to compare something that’s not a Pod::Version return nil

Compares the versions for equality.

Parameters:

  • other (Version)

    The other version to compare.

Returns:

  • (Boolean)

    whether the receiver is equal to other.



144
145
146
# File 'lib/cocoapods-core/version.rb', line 144

def ==(other)
  compare_segments(other) == 0
end

#>=(other) ⇒ Boolean

Note:

Attempts to compare something that’s not a Pod::Version return nil

Compares the versions for equality.

Parameters:

  • other (Version)

    The other version to compare.

Returns:

  • (Boolean)

    whether the receiver is greater than or equal to other.



159
160
161
162
# File 'lib/cocoapods-core/version.rb', line 159

def >=(other)
  comparison = compare_segments(other)
  comparison >= 0
end

#inspectString

Returns a string representation suitable for debugging.

Returns:

  • (String)

    a string representation suitable for debugging.



59
60
61
# File 'lib/cocoapods-core/version.rb', line 59

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

#majorFixnum

Returns The semver major identifier.

Returns:

  • (Fixnum)

    The semver major identifier.



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

def major
  numeric_segments[0].to_i
end

#minorFixnum

Returns The semver minor identifier.

Returns:

  • (Fixnum)

    The semver minor identifier.



108
109
110
# File 'lib/cocoapods-core/version.rb', line 108

def minor
  numeric_segments[1].to_i
end

#patchFixnum

Returns The semver patch identifier.

Returns:

  • (Fixnum)

    The semver patch identifier.



114
115
116
# File 'lib/cocoapods-core/version.rb', line 114

def patch
  numeric_segments[2].to_i
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: semver.org

Returns indicates whether or not the version is a prerelease.

Returns:

  • (Boolean)

    indicates whether or not the version is a prerelease.



70
71
72
73
74
# File 'lib/cocoapods-core/version.rb', line 70

def prerelease?
  return @prerelease if defined?(@prerelease)
  comparable_version = @version.sub(/#{METADATA_PATTERN}$/, '')
  @prerelease = comparable_version =~ /[a-zA-Z\-]/
end

#semantic?Boolean

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:

  • (Boolean)

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



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

def semantic?
  version.to_s =~ ANCHORED_SEMANTIC_VERSION_PATTERN
end