Merge pull request #10407 from SeekingMeaning/version-public-api

version: mark methods as public
This commit is contained in:
Seeker 2021-01-25 18:50:08 -08:00 committed by GitHub
commit acdb05dbcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -93,46 +93,68 @@ module Cask
to_s == "latest"
end
# @api public
sig { returns(T.self_type) }
def major
version { slice(MAJOR_MINOR_PATCH_REGEX, 1) }
end
# @api public
sig { returns(T.self_type) }
def minor
version { slice(MAJOR_MINOR_PATCH_REGEX, 2) }
end
# @api public
sig { returns(T.self_type) }
def patch
version { slice(MAJOR_MINOR_PATCH_REGEX, 3) }
end
# @api public
sig { returns(T.self_type) }
def major_minor
version { [major, minor].reject(&:empty?).join(".") }
end
# @api public
sig { returns(T.self_type) }
def major_minor_patch
version { [major, minor, patch].reject(&:empty?).join(".") }
end
# @api public
sig { returns(T.self_type) }
def minor_patch
version { [minor, patch].reject(&:empty?).join(".") }
end
# @api public
sig { returns(T.self_type) }
def before_comma
version { split(",", 2).first }
end
# @api public
sig { returns(T.self_type) }
def after_comma
version { split(",", 2).second }
end
# @api public
sig { returns(T.self_type) }
def before_colon
version { split(":", 2).first }
end
# @api public
sig { returns(T.self_type) }
def after_colon
version { split(":", 2).second }
end
# @api public
sig { returns(T.self_type) }
def no_dividers
version { gsub(DIVIDER_REGEX, "") }
end

View File

@ -555,26 +555,31 @@ class Version
end
alias eql? ==
# @api public
sig { returns(T.nilable(Token)) }
def major
tokens.first
end
# @api public
sig { returns(T.nilable(Token)) }
def minor
tokens.second
end
# @api public
sig { returns(T.nilable(Token)) }
def patch
tokens.third
end
# @api public
sig { returns(Version) }
def major_minor
Version.new([major, minor].compact.join("."))
end
# @api public
sig { returns(Version) }
def major_minor_patch
Version.new([major, minor, patch].compact.join("."))