Class: Version Private
- Includes:
- Comparable
- Defined in:
- version.rb,
version/parser.rb
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Direct Known Subclasses
Defined Under Namespace
Classes: AlphaToken, BetaToken, CompositeToken, NumericToken, Parser, PatchToken, PostToken, PreToken, RCToken, RegexParser, StemParser, StringToken, Token, UrlParser
Constant Summary collapse
- NULL_TOKEN =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
Represents the absence of a token.
NullToken.new.freeze
Class Method Summary collapse
- .detect(url, **specs) ⇒ Version private
- .formula_optionally_versioned_regex(name, full: true) ⇒ Regexp private
- .parse(spec, detected_from_url: false) ⇒ Version private
Instance Method Summary collapse
- #blank? ⇒ Boolean private
-
#commit ⇒ String?
Return the commit for a HEAD version.
- #compare(comparator, other) ⇒ Boolean private
- #detected_from_url? ⇒ Boolean private
- #freeze ⇒ T.self_type private
-
#head? ⇒ Boolean
Check if this is a HEAD version.
- #initialize(val, detected_from_url: false) ⇒ void constructor private
-
#major ⇒ Token?
The major version.
-
#major_minor ⇒ T.self_type
The major and minor version.
-
#major_minor_patch ⇒ T.self_type
The major, minor and patch version.
-
#minor ⇒ Token?
The minor version.
- #null? ⇒ Boolean private
-
#patch ⇒ Token?
The patch version.
- #respond_to?(method, include_all = false) ⇒ Boolean private
-
#to_f ⇒ Float
Convert the version to a floating-point number.
-
#to_i ⇒ Integer
Convert the version to an integer.
- #to_json(*options) ⇒ String private
- #to_str ⇒ String
-
#update_commit(commit) ⇒ void
private
Update the commit for a HEAD version.
Constructor Details
#initialize(val, detected_from_url: false) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
506 507 508 509 510 511 512 |
# File 'version.rb', line 506 def initialize(val, detected_from_url: false) version = val.to_str raise ArgumentError, "Version must not be empty" if version.blank? @version = T.let(version, String) @detected_from_url = detected_from_url end |
Class Method Details
.detect(url, **specs) ⇒ Version
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
349 350 351 |
# File 'version.rb', line 349 def self.detect(url, **specs) parse(specs.fetch(:tag, url), detected_from_url: true) end |
.formula_optionally_versioned_regex(name, full: true) ⇒ Regexp
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
11 12 13 |
# File 'version.rb', line 11 def self.formula_optionally_versioned_regex(name, full: true) /#{"^" if full}#{Regexp.escape(name)}(?:@\d[\d.]*)?#{"$" if full}/ end |
.parse(spec, detected_from_url: false) ⇒ Version
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'version.rb', line 354 def self.parse(spec, detected_from_url: false) # This type of full-URL decoding is not technically correct but we only need a rough decode for version parsing. spec = URI.decode_www_form_component(spec.to_s) if detected_from_url spec = Pathname(spec) VERSION_PARSERS.each do |parser| version = parser.parse(spec) return new(version, detected_from_url:) if version.present? end NULL end |
Instance Method Details
#blank? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
556 557 558 |
# File 'version.rb', line 556 def blank? version.nil? end |
#commit ⇒ String?
Return the commit for a HEAD version.
534 535 536 |
# File 'version.rb', line 534 def commit version&.match(HEAD_VERSION_REGEX)&.[](:commit) end |
#compare(comparator, other) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
561 562 563 564 565 566 567 568 569 570 571 |
# File 'version.rb', line 561 def compare(comparator, other) case comparator when ">=" then self >= other when ">" then self > other when "<" then self < other when "<=" then self <= other when "==" then self == other when "!=" then self != other else raise ArgumentError, "Unknown comparator: #{comparator}" end end |
#detected_from_url? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
515 516 517 |
# File 'version.rb', line 515 def detected_from_url? @detected_from_url end |
#freeze ⇒ T.self_type
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
773 774 775 776 |
# File 'version.rb', line 773 def freeze tokens # Determine and store tokens before freezing super end |
#head? ⇒ Boolean
Check if this is a HEAD version.
526 527 528 |
# File 'version.rb', line 526 def head? version&.match?(HEAD_VERSION_REGEX) || false end |
#major ⇒ Token?
The major version.
666 667 668 669 670 |
# File 'version.rb', line 666 def major return NULL_TOKEN if null? tokens.first end |
#major_minor ⇒ T.self_type
The major and minor version.
696 697 698 699 700 701 |
# File 'version.rb', line 696 def major_minor return self if null? major_minor = tokens.first(2) major_minor.empty? ? NULL : self.class.new(major_minor.join(".")) end |
#major_minor_patch ⇒ T.self_type
The major, minor and patch version.
707 708 709 710 711 712 |
# File 'version.rb', line 707 def major_minor_patch return self if null? major_minor_patch = tokens.first(3) major_minor_patch.empty? ? NULL : self.class.new(major_minor_patch.join(".")) end |
#minor ⇒ Token?
The minor version.
676 677 678 679 680 |
# File 'version.rb', line 676 def minor return NULL_TOKEN if null? tokens.second end |
#null? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
551 552 553 |
# File 'version.rb', line 551 def null? version.nil? end |
#patch ⇒ Token?
The patch version.
686 687 688 689 690 |
# File 'version.rb', line 686 def patch return NULL_TOKEN if null? tokens.third end |
#respond_to?(method, include_all = false) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
759 760 761 762 763 |
# File 'version.rb', line 759 def respond_to?(method, include_all = false) return !null? if ["to_str", :to_str].include?(method) super end |
#to_f ⇒ Float
Convert the version to a floating-point number.
723 724 725 726 727 |
# File 'version.rb', line 723 def to_f return Float::NAN if null? version.to_f end |
#to_i ⇒ Integer
Convert the version to an integer.
733 734 735 |
# File 'version.rb', line 733 def to_i version.to_i end |
#to_json(*options) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
756 |
# File 'version.rb', line 756 def to_json(*) = version.to_json(*) |
#to_str ⇒ String
742 743 744 745 746 747 |
# File 'version.rb', line 742 def to_str version = self.version raise NoMethodError, "undefined method `to_str` for #{self.class}:NULL" if version.nil? version end |
#update_commit(commit) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
Update the commit for a HEAD version.
540 541 542 543 544 545 546 547 548 |
# File 'version.rb', line 540 def update_commit(commit) raise ArgumentError, "Cannot update commit for non-HEAD version." unless head? @version = if commit "HEAD-#{commit}" else "HEAD" end end |