Class: Pod::Version
- Inherits:
-
Pod::Vendor::Gem::Version
- Object
- Pod::Vendor::Gem::Version
- Pod::Version
- 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.0
-
1.0.b1
-
1.0.a.2
-
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: 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
Semantic Versioning collapse
-
#<=(other) ⇒ Boolean
Compares the versions for equality.
-
#<=>(other) ⇒ Fixnum
Compares the versions for sorting.
-
#==(other) ⇒ Boolean
Compares the versions for equality.
-
#>=(other) ⇒ Boolean
Compares the versions for equality.
-
#major ⇒ Fixnum
The semver major identifier.
-
#minor ⇒ Fixnum
The semver minor identifier.
-
#patch ⇒ Fixnum
The semver patch identifier.
-
#semantic? ⇒ Bool
Whether the version conforms to the Semantic Versioning specification (2.0.0-rc.1).
Class Method Summary collapse
-
.correct?(version) ⇒ Bool
Whether a string representation is correct.
Instance Method Summary collapse
-
#initialize(version) ⇒ Version
constructor
A new instance of Version.
-
#inspect ⇒ String
A string representation suitable for debugging.
-
#prerelease? ⇒ Boolean
Indicates whether or not the version is a prerelease.
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
Remove the ‘HEAD` code once everyone has migrated past 1.0.
Returns a new instance of Version.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cocoapods-core/version.rb', line 46 def initialize(version) if version.is_a?(String) && version =~ /HEAD based on (.*)/ CoreUI.warn "Ignoring obsolete HEAD specifier in `#{version}`" version = Regexp.last_match[1] end raise ArgumentError, "Malformed version number string #{version}" unless self.class.correct?(version) @version = version.to_s.strip end |
Class Method Details
.correct?(version) ⇒ Bool
Returns Whether a string representation is correct.
81 82 83 |
# File 'lib/cocoapods-core/version.rb', line 81 def self.correct?(version) version.to_s =~ ANCHORED_VERSION_PATTERN end |
Instance Method Details
#<=(other) ⇒ Boolean
Attempts to compare something that’s not a Pod::Version return nil
Compares the versions for equality.
178 179 180 181 |
# File 'lib/cocoapods-core/version.rb', line 178 def <=(other) comparison = compare_segments(other) comparison <= 0 end |
#<=>(other) ⇒ Fixnum
Attempts to compare something that’s not a Pod::Version return nil
Compares the versions for sorting.
131 132 133 134 |
# File 'lib/cocoapods-core/version.rb', line 131 def <=>(other) comparison = compare_segments(other) comparison == 0 ? version <=> other.version : comparison end |
#==(other) ⇒ Boolean
Attempts to compare something that’s not a Pod::Version return nil
Compares the versions for equality.
147 148 149 |
# File 'lib/cocoapods-core/version.rb', line 147 def ==(other) compare_segments(other) == 0 end |
#>=(other) ⇒ Boolean
Attempts to compare something that’s not a Pod::Version return nil
Compares the versions for equality.
162 163 164 165 |
# File 'lib/cocoapods-core/version.rb', line 162 def >=(other) comparison = compare_segments(other) comparison >= 0 end |
#inspect ⇒ String
Returns a string representation suitable for debugging.
64 65 66 |
# File 'lib/cocoapods-core/version.rb', line 64 def inspect "<#{self.class} version=#{version}>" end |
#major ⇒ Fixnum
Returns The semver major identifier.
105 106 107 |
# File 'lib/cocoapods-core/version.rb', line 105 def major numeric_segments[0].to_i end |
#minor ⇒ Fixnum
Returns The semver minor identifier.
111 112 113 |
# File 'lib/cocoapods-core/version.rb', line 111 def minor numeric_segments[1].to_i end |
#patch ⇒ Fixnum
Returns The semver patch identifier.
117 118 119 |
# File 'lib/cocoapods-core/version.rb', line 117 def patch numeric_segments[2].to_i end |
#prerelease? ⇒ Boolean
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.
75 76 77 |
# File 'lib/cocoapods-core/version.rb', line 75 def prerelease? @prerelease ||= @version =~ /[a-zA-Z\-]/ end |
#semantic? ⇒ Bool
This comparison is lenient.
It doesn’t support build identifiers.
Returns Whether the version conforms to the Semantic Versioning specification (2.0.0-rc.1).
99 100 101 |
# File 'lib/cocoapods-core/version.rb', line 99 def semantic? version.to_s =~ ANCHORED_SEMANTIC_VERSION_PATTERN end |