Class: Bosh::Common::Version::SemiSemanticVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/common/version/semi_semantic_version.rb

Direct Known Subclasses

BoshVersion, ReleaseVersion, StemcellVersion

Constant Summary collapse

DEFAULT_POST_RELEASE_SEGMENT =
SemiSemantic::VersionSegment.parse('build.1')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ SemiSemanticVersion

Returns a new instance of SemiSemanticVersion.

Raises:

  • (ArgumentError)


25
26
27
28
29
# File 'lib/common/version/semi_semantic_version.rb', line 25

def initialize(version)
  raise ArgumentError, "Invalid Version Type: #{version.class}" unless version.is_a?(SemiSemantic::Version)
  @version = version
  @version.freeze
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



12
13
14
# File 'lib/common/version/semi_semantic_version.rb', line 12

def version
  @version
end

Class Method Details

.parse(version) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
# File 'lib/common/version/semi_semantic_version.rb', line 14

def self.parse(version)
  raise ArgumentError, 'Invalid Version: nil' if version.nil?
  version = version.to_s

  self.new(SemiSemantic::Version.parse(version))
end

.parse_and_compare(a, b) ⇒ Object



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

def self.parse_and_compare(a, b)
  self.parse(a) <=> self.parse(b)
end

Instance Method Details

#<=>(other) ⇒ Object



48
49
50
# File 'lib/common/version/semi_semantic_version.rb', line 48

def <=>(other)
  @version <=> other.version
end

#default_post_releaseObject



31
32
33
# File 'lib/common/version/semi_semantic_version.rb', line 31

def default_post_release
  self.class.new(SemiSemantic::Version.new(@version.release, @version.pre_release, default_post_release_segment))
end

#increment_post_releaseObject



35
36
37
38
# File 'lib/common/version/semi_semantic_version.rb', line 35

def increment_post_release
  raise UnavailableMethodError, 'Failed to increment: post-release is nil' if @version.post_release.nil?
  self.class.new(SemiSemantic::Version.new(@version.release, @version.pre_release, @version.post_release.increment))
end

#increment_releaseObject



40
41
42
# File 'lib/common/version/semi_semantic_version.rb', line 40

def increment_release
  self.class.new(SemiSemantic::Version.new(@version.release.increment))
end

#timestamp_releaseObject



44
45
46
# File 'lib/common/version/semi_semantic_version.rb', line 44

def timestamp_release
  self.class.new(SemiSemantic::Version.new(@version.release, @version.pre_release, SemiSemantic::VersionSegment.parse("dev." + Time.now.to_i.to_s)))
end

#to_sObject



52
53
54
# File 'lib/common/version/semi_semantic_version.rb', line 52

def to_s
  @version.to_s
end