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, tag: nil) ⇒ 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.
519 520 521 522 523 524 525 |
# File 'version.rb', line 519 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, tag: nil) ⇒ 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.
361 362 363 |
# File 'version.rb', line 361 def self.detect(url, tag: nil) parse(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 14 15 16 17 18 |
# File 'version.rb', line 11 def self.formula_optionally_versioned_regex(name, full: true) name = name.to_s suffix = "-full" if name.end_with?("-full") anchor_start = full ? "^" : "" name_pattern = Regexp.escape(name.delete_suffix("-full")) anchor_end = full ? "$" : "" /#{anchor_start}#{name_pattern}(?:@\d[\d.]*)?#{suffix}#{anchor_end}/ 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.
366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'version.rb', line 366 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.
569 570 571 |
# File 'version.rb', line 569 def blank? version.nil? end |
#commit ⇒ String?
Return the commit for a HEAD version.
547 548 549 |
# File 'version.rb', line 547 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.
574 575 576 577 578 579 580 581 582 583 584 |
# File 'version.rb', line 574 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.
528 529 530 |
# File 'version.rb', line 528 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.
811 812 813 814 |
# File 'version.rb', line 811 def freeze tokens # Determine and store tokens before freezing super end |
#head? ⇒ Boolean
Check if this is a HEAD version.
539 540 541 |
# File 'version.rb', line 539 def head? version&.match?(HEAD_VERSION_REGEX) || false end |
#major ⇒ Token?
The major version.
690 691 692 693 694 |
# File 'version.rb', line 690 def major return NULL_TOKEN if null? tokens.first end |
#major_minor ⇒ T.self_type
The major and minor version.
720 721 722 723 724 725 726 727 728 729 |
# File 'version.rb', line 720 def major_minor return self if null? major_minor = tokens.first(2) if major_minor.empty? NULL else self.class.new(major_minor.join(".")) end end |
#major_minor_patch ⇒ T.self_type
The major, minor and patch version.
735 736 737 738 739 740 741 742 743 744 |
# File 'version.rb', line 735 def major_minor_patch return self if null? major_minor_patch = tokens.first(3) if major_minor_patch.empty? NULL else self.class.new(major_minor_patch.join(".")) end end |
#minor ⇒ Token?
The minor version.
700 701 702 703 704 |
# File 'version.rb', line 700 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.
564 565 566 |
# File 'version.rb', line 564 def null? version.nil? end |
#patch ⇒ Token?
The patch version.
710 711 712 713 714 |
# File 'version.rb', line 710 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.
797 798 799 800 801 |
# File 'version.rb', line 797 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.
761 762 763 764 765 |
# File 'version.rb', line 761 def to_f return Float::NAN if null? version.to_f end |
#to_i ⇒ Integer
Convert the version to an integer.
771 772 773 |
# File 'version.rb', line 771 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.
794 |
# File 'version.rb', line 794 def to_json(*) = version.to_json(*) |
#to_str ⇒ String
780 781 782 783 784 785 |
# File 'version.rb', line 780 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.
553 554 555 556 557 558 559 560 561 |
# File 'version.rb', line 553 def update_commit(commit) raise ArgumentError, "Cannot update commit for non-HEAD version." unless head? @version = if commit "HEAD-#{commit}" else "HEAD" end end |