Class: Cask::DSL::Version Private

Inherits:
String
  • Object
show all
Defined in:
Library/Homebrew/cask/dsl/version.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class corresponding to the version stanza.

Constant Summary collapse

DIVIDERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  "." => :dots,
  "-" => :hyphens,
  "_" => :underscores,
}.freeze
DIVIDER_REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join('|')})/.freeze
MAJOR_MINOR_PATCH_REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/^([^.,:]+)(?:.([^.,:]+)(?:.([^.,:]+))?)?/.freeze
INVALID_CHARACTERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/[^0-9a-zA-Z.,:\-_]/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from String

#f, #undent

Constructor Details

#initialize(raw_version) ⇒ Version

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Version.


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

def initialize(raw_version)
  @raw_version = raw_version
  super(raw_version.to_s)
end

Instance Attribute Details

#raw_versionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


63
64
65
# File 'Library/Homebrew/cask/dsl/version.rb', line 63

def raw_version
  @raw_version
end

Instance Method Details

#after_colonObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


127
128
129
# File 'Library/Homebrew/cask/dsl/version.rb', line 127

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

#after_commaObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

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

#before_colonObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


123
124
125
# File 'Library/Homebrew/cask/dsl/version.rb', line 123

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

#before_commaObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


115
116
117
# File 'Library/Homebrew/cask/dsl/version.rb', line 115

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

#invalid_charactersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

def invalid_characters
  return [] if latest?

  raw_version.scan(INVALID_CHARACTERS)
end

#latest?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

87
88
89
# File 'Library/Homebrew/cask/dsl/version.rb', line 87

def latest?
  to_s == "latest"
end

#majorObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


91
92
93
# File 'Library/Homebrew/cask/dsl/version.rb', line 91

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

#major_minorObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


103
104
105
# File 'Library/Homebrew/cask/dsl/version.rb', line 103

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

#major_minor_patchObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

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

#minorObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

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

#minor_patchObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


111
112
113
# File 'Library/Homebrew/cask/dsl/version.rb', line 111

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

#no_dividersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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

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

#patchObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


99
100
101
# File 'Library/Homebrew/cask/dsl/version.rb', line 99

def patch
  version { slice(MAJOR_MINOR_PATCH_REGEX, 3) }
end

#unstable?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

76
77
78
79
80
81
82
83
84
85
# File 'Library/Homebrew/cask/dsl/version.rb', line 76

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