Class: Cask::DSL::Version Private

Inherits:
String
  • Object
show all
Extended by:
T::Sig
Defined in:
cask/dsl/version.rb

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.

{
  "." => :dots,
  "-" => :hyphens,
  "_" => :underscores,
}.freeze
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.

/(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join('|')})/.freeze
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.

/^([^.,:]+)(?:.([^.,:]+)(?:.([^.,:]+))?)?/.freeze
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.,:\-_+ ]/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from String

#f, #undent

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.

Parameters:

Raises:

  • (TypeError)


68
69
70
71
72
73
74
# File 'cask/dsl/version.rb', line 68

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_versionObject (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.



65
66
67
# File 'cask/dsl/version.rb', line 65

def raw_version
  @raw_version
end

Instance Method Details

#after_colonT.self_type

Returns:

  • (T.self_type)


155
156
157
# File 'cask/dsl/version.rb', line 155

def after_colon
  version { split(":", 2).second }
end

#after_commaT.self_type

Returns:

  • (T.self_type)


143
144
145
# File 'cask/dsl/version.rb', line 143

def after_comma
  version { split(",", 2).second }
end

#before_colonT.self_type

Returns:

  • (T.self_type)


149
150
151
# File 'cask/dsl/version.rb', line 149

def before_colon
  version { split(":", 2).first }
end

#before_commaT.self_type

Returns:

  • (T.self_type)


137
138
139
# File 'cask/dsl/version.rb', line 137

def before_comma
  version { split(",", 2).first }
end

#invalid_charactersObject

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.



76
77
78
79
80
# File 'cask/dsl/version.rb', line 76

def invalid_characters
  return [] if raw_version.blank? || latest?

  raw_version.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.

Returns:

  • (Boolean)


95
96
97
# File 'cask/dsl/version.rb', line 95

def latest?
  to_s == "latest"
end

#majorT.self_type

Returns:

  • (T.self_type)


101
102
103
# File 'cask/dsl/version.rb', line 101

def major
  version { slice(MAJOR_MINOR_PATCH_REGEX, 1) }
end

#major_minorT.self_type

Returns:

  • (T.self_type)


119
120
121
# File 'cask/dsl/version.rb', line 119

def major_minor
  version { [major, minor].reject(&:empty?).join(".") }
end

#major_minor_patchT.self_type

Returns:

  • (T.self_type)


125
126
127
# File 'cask/dsl/version.rb', line 125

def major_minor_patch
  version { [major, minor, patch].reject(&:empty?).join(".") }
end

#minorT.self_type

Returns:

  • (T.self_type)


107
108
109
# File 'cask/dsl/version.rb', line 107

def minor
  version { slice(MAJOR_MINOR_PATCH_REGEX, 2) }
end

#minor_patchT.self_type

Returns:

  • (T.self_type)


131
132
133
# File 'cask/dsl/version.rb', line 131

def minor_patch
  version { [minor, patch].reject(&:empty?).join(".") }
end

#no_dividersT.self_type

Returns:

  • (T.self_type)


161
162
163
# File 'cask/dsl/version.rb', line 161

def no_dividers
  version { gsub(DIVIDER_REGEX, "") }
end

#patchT.self_type

Returns:

  • (T.self_type)


113
114
115
# File 'cask/dsl/version.rb', line 113

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.

Returns:

  • (Boolean)


83
84
85
86
87
88
89
90
91
92
# File 'cask/dsl/version.rb', line 83

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