Class: Bosh::Common::Version::VersionList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/common/version/version_list.rb

Direct Known Subclasses

ReleaseVersionList, StemcellVersionList

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(versions) ⇒ VersionList

Returns a new instance of VersionList.

Parameters:

  • Collection (Array<#version>)

    of SemiSemanticVersion objects

Raises:

  • (TypeError)


20
21
22
23
# File 'lib/common/version/version_list.rb', line 20

def initialize(versions)
  raise TypeError, "Invalid Version Array: '#{versions.inspect}'" unless versions.kind_of?(Array)
  @versions = versions
end

Instance Attribute Details

#versionsObject (readonly)

Returns the value of attribute versions.



8
9
10
# File 'lib/common/version/version_list.rb', line 8

def versions
  @versions
end

Class Method Details

.parse(versions, version_type) ⇒ Object

Parameters:

  • Collection (Array<#version>)

    of version strings

  • Version (class)

    type to parse as (ex: SemiSemanticVersion, ReleaseVersion, StemcellVersion, BoshVersion)

Raises:

  • (TypeError)


14
15
16
17
# File 'lib/common/version/version_list.rb', line 14

def self.parse(versions, version_type)
  raise TypeError, "Failed to Parse - Invalid Version Type: '#{version_type.inspect}'" unless version_type <= SemiSemanticVersion
  self.new(versions.map { |v| version_type.parse(v) })
end

Instance Method Details

#==(other) ⇒ Object



47
48
49
# File 'lib/common/version/version_list.rb', line 47

def ==(other)
  @versions == other.versions
end

#each(&block) ⇒ Object



43
44
45
# File 'lib/common/version/version_list.rb', line 43

def each(&block)
  @versions.each(&block)
end

#latest_with_pre_release(version) ⇒ Object

Gets the latest version with the same release and pre-release version as the specified version

Parameters:

  • SemiSemanticVersion (#version)

    object

Raises:

  • (TypeError)


27
28
29
30
31
32
# File 'lib/common/version/version_list.rb', line 27

def latest_with_pre_release(version)
  raise TypeError, "Invalid Version Type: #{version.class}" unless version.kind_of?(SemiSemanticVersion)
  @versions.select { |v|
    v.version.release == version.version.release && v.version.pre_release == version.version.pre_release
  }.max
end

#latest_with_release(version) ⇒ Object

Gets the latest version with the same release version as the specified version

Parameters:

  • SemiSemanticVersion (#version)

    object

Raises:

  • (TypeError)


36
37
38
39
40
41
# File 'lib/common/version/version_list.rb', line 36

def latest_with_release(version)
  raise TypeError, "Invalid Version Type: #{version.class}" unless version.kind_of?(SemiSemanticVersion)
  @versions.select { |v|
    v.version.release == version.version.release
  }.max
end

#to_sObject



51
52
53
# File 'lib/common/version/version_list.rb', line 51

def to_s
  @versions.map{ |v| v.to_s }.to_s
end