Class: Version Private
- Includes:
- Comparable
- Defined in:
- version.rb,
version/parser.rb,
version.rbi
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
-
.create(val) ⇒ Version
private
-
.detect(url, **specs) ⇒ Version
private
-
.formula_optionally_versioned_regex(name, full: true) ⇒ Regexp
private
-
.parse(spec, detected_from_url: false) ⇒ T.attached_class
private
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
private
-
#==(other) ⇒ Boolean
(also: #eql?)
private
For
alias eql? ==
See discussions: - https://github.com/sorbet/sorbet/pull/1443 - https://github.com/sorbet/sorbet/issues/2378. -
#commit ⇒ String?
private
Return the commit for a HEAD version.
-
#compare(comparator, other) ⇒ Boolean
private
-
#detected_from_url? ⇒ Boolean
private
-
#freeze ⇒ T.self_type
private
-
#hash ⇒ Integer
private
-
#head? ⇒ Boolean
private
Check if this is a HEAD version.
-
#initialize(val, detected_from_url: false) ⇒ void
constructor
private
-
#major ⇒ Token?
-
#major_minor ⇒ T.self_type
-
#major_minor_patch ⇒ T.self_type
-
#minor ⇒ Token?
-
#null? ⇒ Boolean
private
-
#patch ⇒ Token?
-
#respond_to?(method, include_all = T.unsafe(nil)) ⇒ Boolean
private
-
#to_f ⇒ Float
private
-
#to_i ⇒ Integer
private
-
#to_json(*options) ⇒ String
private
-
#to_str ⇒ String
private
-
#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.
502 503 504 505 506 507 508 |
# File 'version.rb', line 502 def initialize(val, detected_from_url: false) version = val.to_str raise ArgumentError, "Version must not be empty" if version.blank? @version = version @detected_from_url = detected_from_url end |
Class Method Details
.create(val) ⇒ 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.
352 353 354 355 |
# File 'version.rb', line 352 def self.create(val) odisabled "Version.create", "Version.new" new(val) end |
.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.
347 348 349 |
# File 'version.rb', line 347 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.
12 13 14 |
# File 'version.rb', line 12 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) ⇒ T.attached_class
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.
358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'version.rb', line 358 def self.parse(spec, detected_from_url: false) spec = CGI.unescape(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
#<=>(other) ⇒ Integer?
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 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
# File 'version.rb', line 561 def <=>(other) other = case other when String if other.blank? # Cannot compare `NULL` to empty string. return if null? return 1 end # Needed to retain API compatibility with older string comparisons for compiler versions, etc. Version.new(other) when Integer # Used by the `*_build_version` comparisons, which formerly returned an integer. Version.new(other.to_s) when Token if other.null? # Cannot compare `NULL` to `NULL`. return if null? return 1 end Version.new(other.to_s) when Version if other.null? # Cannot compare `NULL` to `NULL`. return if null? return 1 end other when nil return 1 else return end # All `other.null?` cases are handled at this point. return -1 if null? return 0 if version == other.version return 1 if head? && !other.head? return -1 if !head? && other.head? return 0 if head? && other.head? ltokens = tokens rtokens = other.tokens max = max(ltokens.length, rtokens.length) l = r = 0 while l < max a = ltokens[l] || NULL_TOKEN b = rtokens[r] || NULL_TOKEN if a == b l += 1 r += 1 next elsif a.numeric? && !b.numeric? return 1 if a > NULL_TOKEN l += 1 elsif !a.numeric? && b.numeric? return -1 if b > NULL_TOKEN r += 1 else return a <=> b end end 0 end |
#==(other) ⇒ Boolean Also known as: eql?
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.
For alias eql? ==
See discussions:
- https://github.com/sorbet/sorbet/pull/1443
- https://github.com/sorbet/sorbet/issues/2378
638 639 640 641 642 643 644 645 646 |
# File 'version.rb', line 638 def ==(other) # Makes sure that the same instance of Version::NULL # will never equal itself; normally Comparable#== # will return true for this regardless of the return # value of #<=> return false if null? super end |
#commit ⇒ 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.
Return the commit for a HEAD version.
526 527 528 |
# File 'version.rb', line 526 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.
548 549 550 551 552 553 554 555 556 557 558 |
# File 'version.rb', line 548 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.
511 512 513 |
# File 'version.rb', line 511 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.
740 741 742 743 |
# File 'version.rb', line 740 def freeze tokens # Determine and store tokens before freezing super end |
#hash ⇒ Integer
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.
692 693 694 |
# File 'version.rb', line 692 def hash version.hash end |
#head? ⇒ 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.
Check if this is a HEAD version.
520 521 522 |
# File 'version.rb', line 520 def head? version&.match?(HEAD_VERSION_REGEX) || false end |
#major ⇒ Token?
651 652 653 654 655 |
# File 'version.rb', line 651 def major return NULL_TOKEN if null? tokens.first end |
#major_minor ⇒ T.self_type
675 676 677 678 679 680 |
# File 'version.rb', line 675 def major_minor return self if null? major_minor = T.must(tokens[0..1]) major_minor.empty? ? NULL : self.class.new(major_minor.join(".")) end |
#major_minor_patch ⇒ T.self_type
684 685 686 687 688 689 |
# File 'version.rb', line 684 def major_minor_patch return self if null? major_minor_patch = T.must(tokens[0..2]) major_minor_patch.empty? ? NULL : self.class.new(major_minor_patch.join(".")) end |
#minor ⇒ Token?
659 660 661 662 663 |
# File 'version.rb', line 659 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.
543 544 545 |
# File 'version.rb', line 543 def null? version.nil? end |
#patch ⇒ Token?
667 668 669 670 671 |
# File 'version.rb', line 667 def patch return NULL_TOKEN if null? tokens.third end |
#respond_to?(method, include_all = T.unsafe(nil)) ⇒ 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.
725 726 727 728 729 |
# File 'version.rb', line 725 def respond_to?(method, include_all = T.unsafe(nil)) return !null? if ["to_str", :to_str].include?(method) super end |
#to_f ⇒ Float
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.
697 698 699 700 701 |
# File 'version.rb', line 697 def to_f return Float::NAN if null? version.to_f end |
#to_i ⇒ Integer
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.
704 705 706 |
# File 'version.rb', line 704 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.
720 721 722 |
# File 'version.rb', line 720 def to_json(*) version.to_json(*) end |
#to_str ⇒ 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.
709 710 711 712 713 |
# File 'version.rb', line 709 def to_str raise NoMethodError, "undefined method `to_str' for #{self.class}:NULL" if null? T.must(version).to_str 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.
532 533 534 535 536 537 538 539 540 |
# File 'version.rb', line 532 def update_commit(commit) raise ArgumentError, "Cannot update commit for non-HEAD version." unless head? @version = if commit "HEAD-#{commit}" else "HEAD" end end |