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.

Examples:

module Version
  extend SleepingKingStudios::Tools::SemanticVersion

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

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

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

See Also:

Defined Under Namespace

Classes: InvalidVersionError

Instance Method Summary collapse

Instance Method Details

#to_gem_versionString

Generates a RubyGems-compatible version string.

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

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

Raises:



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sleeping_king_studios/tools/toolbox/semantic_version.rb', line 58

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

Generates a standard Semver version string.

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

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

Raises:



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/sleeping_king_studios/tools/toolbox/semantic_version.rb', line 96

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