Class: BuildpackSupport::TokenizedVersion

Inherits:
Array
  • Object
show all
Includes:
Comparable
Defined in:
lib/buildpack_support/tokenized_version.rb

Overview

A utility for manipulating JRE version numbers.

Constant Summary collapse

WILDCARD =

The wildcard component.

'+'

Instance Method Summary collapse

Constructor Details

#initialize(version, allow_wildcards = true) ⇒ TokenizedVersion

Create a tokenized version based on the input string.

Parameters:

  • version (String)

    a version string

  • allow_wildcards (Boolean) (defaults to: true)

    whether or not to allow ‘+’ as the last component to represent a wildcard



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/buildpack_support/tokenized_version.rb', line 31

def initialize(version, allow_wildcards = true)
  @version = version
  @version = WILDCARD if !@version && allow_wildcards

  major, tail      = major_or_minor_and_tail @version
  minor, tail      = major_or_minor_and_tail tail
  micro, qualifier = micro_and_qualifier tail

  concat [major, minor, micro, qualifier]
  validate allow_wildcards
end

Instance Method Details

#<=>(other) ⇒ Integer

Compare this to another array

Returns:

  • (Integer)

    A numerical representation of the comparison between two instances



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/buildpack_support/tokenized_version.rb', line 46

def <=>(other)
  comparison = 0
  i          = 0
  while comparison == 0 && i < 3
    comparison = self[i].to_i <=> other[i].to_i
    i          += 1
  end
  comparison = qualifier_compare(non_nil_qualifier(self[3]), non_nil_qualifier(other[3])) if comparison == 0

  comparison
end

#check_size(maximum_components) ⇒ Object

Check that this version has at most the given number of components.

Parameters:

  • maximum_components (Integer)

    the maximum number of components this version is allowed to have

Raises:

  • if this version has more than the given number of components



69
70
71
# File 'lib/buildpack_support/tokenized_version.rb', line 69

def check_size(maximum_components)
  fail "Malformed version #{self}: too many version components" if self[maximum_components]
end

#to_sString

Convert this to a string

Returns:

  • (String)

    a string representation of this tokenized version



61
62
63
# File 'lib/buildpack_support/tokenized_version.rb', line 61

def to_s
  @version
end