Module: SleepingKingStudios::Tools::Toolbox::SemanticVersion

Included in:
Version
Defined in:
lib/sleeping_king_studios/tools/toolbox/semantic_version.rb

Overview

Helper for generating semantic version strings with optional prerelease and build parameters.

Examples:

module Version
  extend SleepingKingStudios::Tools::SemanticVersion

  MAJOR = 3
  MINOR = 1
  PATCH = 4
  PRERELEASE = 'beta'
  BUILD = 1
end # module

VERSION = Version.to_gem_version

See Also:

Defined Under Namespace

Classes: InvalidVersionError

Instance Method Summary collapse

Instance Method Details

#to_gem_versionString

Concatenates the MAJOR, MINOR, and PATCH constant values with PRERELEASE and BUILD (if available) to generate a modified semantic version string compatible with Rubygems. The major, minor, patch, prerelease, and build values (if available) are separated by dots (.).

Examples:

module Version
  extend SleepingKingStudios::Tools::SemanticVersion

  MAJOR = 3
  MINOR = 1
  PATCH = 4
  PRERELEASE = 'beta'
  BUILD = 1
end # module

VERSION = Version.to_gem_version
#=> '3.1.4.beta.1'

Returns:

  • (String)

    The modified semantic version string.

Raises:

  • InvalidVersionError If MAJOR, MINOR, or PATCH is undefined.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sleeping_king_studios/tools/toolbox/semantic_version.rb', line 49

def to_gem_version
  str = +"#{const_fetch :MAJOR}.#{const_fetch :MINOR}.#{const_fetch :PATCH}"

  prerelease = const_fetch(:PRERELEASE, nil)
  str << ".#{prerelease}" unless prerelease.nil? || prerelease.empty?

  build = const_fetch(:BUILD, nil)
  str << ".#{build}" unless build.nil? || build.empty?

  str
end

#to_versionString

Concatenates the MAJOR, MINOR, and PATCH constant values with PRERELEASE and BUILD (if available) to generate a semantic version string. The major, minor, and patch values are separated by dots (.), then the prerelease (if available) preceded by a hyphen (-), and the build (if available) preceded by a plus (+).

Examples:

module Version
  extend SleepingKingStudios::Tools::SemanticVersion

  MAJOR = 3
  MINOR = 1
  PATCH = 4
  PRERELEASE = 'beta'
  BUILD = 1
end # module

VERSION = Version.to_version
#=> '3.1.4-beta+1'

Returns:

  • (String)

    The semantic version string.

Raises:

  • InvalidVersionError If MAJOR, MINOR, or PATCH is undefined.



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/sleeping_king_studios/tools/toolbox/semantic_version.rb', line 84

def to_version
  str = +"#{const_fetch :MAJOR}.#{const_fetch :MINOR}.#{const_fetch :PATCH}"

  prerelease = const_fetch(:PRERELEASE, nil)
  str << "-#{prerelease}" unless prerelease.nil? || prerelease.empty?

  build = const_fetch(:BUILD, nil)
  str << "+#{build}" unless build.nil? || build.empty?

  str
end