Class: Cask::DSL::Version Private
Overview
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.
Class corresponding to the version stanza.
Constant Summary collapse
- DIVIDERS =
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.
T.let({ "." => :dots, "-" => :hyphens, "_" => :underscores, }.freeze, T::Hash[String, Symbol])
- DIVIDER_REGEX =
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.
/(?:#{divider_pattern})/- MAJOR_MINOR_PATCH_REGEX =
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.
/^([^.,:]+)(?:.([^.,:]+)(?:.([^.,:]+))?)?/- INVALID_CHARACTERS =
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.
/[^0-9a-zA-Z.,:\-_+ ]/
Constants inherited from String
String::BLANK_RE, String::ENCODED_BLANKS_
Instance Attribute Summary collapse
- #raw_version ⇒ String, ... readonly private
Instance Method Summary collapse
-
#after_comma ⇒ T.self_type
The version part after the first comma.
-
#before_comma ⇒ T.self_type
The version part before the first comma.
-
#chomp(separator = nil) ⇒ T.self_type
The version with the given record separator removed from the end.
-
#csv ⇒ Array<Version>
The comma separated values of the version as array.
- #initialize(raw_version) ⇒ void constructor private
- #invalid_characters ⇒ Array<Array<String>, String> private
- #latest? ⇒ Boolean private
-
#major ⇒ T.self_type
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 ⇒ T.self_type
The minor version.
-
#minor_patch ⇒ T.self_type
The minor and patch version.
-
#no_dividers ⇒ T.self_type
The version without any dividers.
-
#patch ⇒ T.self_type
The patch version.
- #unstable? ⇒ Boolean private
Methods inherited from String
Constructor Details
#initialize(raw_version) ⇒ 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.
74 75 76 77 78 79 80 |
# File 'cask/dsl/version.rb', line 74 def initialize(raw_version) @raw_version = raw_version super(raw_version.to_s) invalid = invalid_characters raise TypeError, "#{raw_version} contains invalid characters: #{invalid.uniq.join}!" if invalid.present? end |
Instance Attribute Details
#raw_version ⇒ String, ... (readonly)
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.
71 72 73 |
# File 'cask/dsl/version.rb', line 71 def raw_version @raw_version end |
Instance Method Details
#after_comma ⇒ T.self_type
The version part after the first comma.
174 175 176 |
# File 'cask/dsl/version.rb', line 174 def after_comma version { split(",", 2).second } end |
#before_comma ⇒ T.self_type
The version part before the first comma.
166 167 168 |
# File 'cask/dsl/version.rb', line 166 def before_comma version { split(",", 2).first } end |
#chomp(separator = nil) ⇒ T.self_type
The version with the given record separator removed from the end.
192 193 194 |
# File 'cask/dsl/version.rb', line 192 def chomp(separator = nil) version { separator ? to_s.chomp(separator) : to_s.chomp } end |
#csv ⇒ Array<Version>
The comma separated values of the version as array.
158 159 160 |
# File 'cask/dsl/version.rb', line 158 def csv split(",").map { self.class.new(it) } end |
#invalid_characters ⇒ Array<Array<String>, 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.
83 84 85 86 87 |
# File 'cask/dsl/version.rb', line 83 def invalid_characters return [] if raw_version.blank? || latest? raw_version.to_s.scan(INVALID_CHARACTERS) end |
#latest? ⇒ 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.
102 103 104 |
# File 'cask/dsl/version.rb', line 102 def latest? to_s == "latest" end |
#major ⇒ T.self_type
The major version.
110 111 112 |
# File 'cask/dsl/version.rb', line 110 def major version { slice(MAJOR_MINOR_PATCH_REGEX, 1) } end |
#major_minor ⇒ T.self_type
The major and minor version.
134 135 136 |
# File 'cask/dsl/version.rb', line 134 def major_minor version { [major, minor].reject(&:empty?).join(".") } end |
#major_minor_patch ⇒ T.self_type
The major, minor and patch version.
142 143 144 |
# File 'cask/dsl/version.rb', line 142 def major_minor_patch version { [major, minor, patch].reject(&:empty?).join(".") } end |
#minor ⇒ T.self_type
The minor version.
118 119 120 |
# File 'cask/dsl/version.rb', line 118 def minor version { slice(MAJOR_MINOR_PATCH_REGEX, 2) } end |
#minor_patch ⇒ T.self_type
The minor and patch version.
150 151 152 |
# File 'cask/dsl/version.rb', line 150 def minor_patch version { [minor, patch].reject(&:empty?).join(".") } end |
#no_dividers ⇒ T.self_type
The version without any dividers.
183 184 185 |
# File 'cask/dsl/version.rb', line 183 def no_dividers version { gsub(DIVIDER_REGEX, "") } end |
#patch ⇒ T.self_type
The patch version.
126 127 128 |
# File 'cask/dsl/version.rb', line 126 def patch version { slice(MAJOR_MINOR_PATCH_REGEX, 3) } end |
#unstable? ⇒ 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.
90 91 92 93 94 95 96 97 98 99 |
# File 'cask/dsl/version.rb', line 90 def unstable? return false if latest? s = downcase.delete(".").gsub(/[^a-z\d]+/, "-") return true if s.match?(/(\d+|\b)(alpha|beta|preview|rc|dev|canary|snapshot)(\d+|\b)/i) return true if s.match?(/\A[a-z\d]+(-\d+)*-?(a|b|pre)(\d+|\b)/i) false end |