Class: Complish::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/complish/version.rb

Overview

Note:

Complish uses the SemVer 2.0.0 versioning format.

The Complish version number

See Also:

Author:

Since:

  • 0.2.0-alpha

Version:

  • 2.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeComplish::Version

Create a new instance of Version

Examples:

Create a new instance of version

Complish::Version.new
 #=> <#Complish::Version>

Since:

  • 0.2.0-alpha

Version:

  • 1.0


23
24
25
# File 'lib/complish/version.rb', line 23

def initialize
  @version ||= SemVer.find
end

Instance Attribute Details

#versionXSemVer::SemVer (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the class instance of version.

Since:

  • 0.2.0-alpha


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/complish/version.rb', line 14

class Version
  attr_reader :version

  # Create a new instance of Version
  # @version 1.0
  # @example Create a new instance of version
  #  Complish::Version.new
  #   #=> <#Complish::Version>
  # @return [Complish::Version] the new instance of version
  def initialize
    @version ||= SemVer.find
  end

  # Get the whole version number
  # @version 1.0
  # @example Get the whole Semver version
  #  Complish::Version.whole
  #   #=> '0.2.0-alpha'
  # @example get version whole with prefix
  #  Complish::Version.whole(true)
  #   #=> 'v0.2.0-alpha'
  # @param [Boolean] prefix whether or not to prepend 'v' to the version string
  # @return [String] the whole version string
  def self.whole(prefix = false)
    format_exp = prefix ? 'v%M.%m.%p%s%d' : '%M.%m.%p%s%d'
    new.version.format(format_exp).freeze
  end

  # Get the major minor patch versions
  # @version 1.0
  # @example Get version main
  #  Complish::Version.main
  #   #=> '0.2.0'
  # @example Get version main with prefix
  #  Complish::Version.main(true)
  #   #=> 'v0.2.0'
  # @param [Boolean] prefix whether or not to prepend 'v' to the version string
  # @return [String] the main version part
  def self.main(prefix = false)
    format_exp = prefix ? 'v%M.%m.%p' : '%M.%m.%p'
    new.version.format(format_exp).freeze
  end

  # Get the version pre-release data
  # @version 1.0
  # @example Get version pre-release
  #  Complish::Version.pre
  #   #=> 'alpha'
  # @return [String, nil] the version pre-release data
  def self.pre
    new.version.prerelease
  end

  # Get the version meta-data
  # @version 1.0
  # @example Get version meta-data
  #  Complish::Version.meta
  #   #=> 'nightly1234'
  # @return [String, nil] the version meta-data
  def self.meta
    new.version.
  end
end

Class Method Details

.main(prefix = false) ⇒ String

Get the major minor patch versions

Examples:

Get version main

Complish::Version.main
 #=> '0.2.0'

Get version main with prefix

Complish::Version.main(true)
 #=> 'v0.2.0'

Since:

  • 0.2.0-alpha

Version:

  • 1.0


52
53
54
55
# File 'lib/complish/version.rb', line 52

def self.main(prefix = false)
  format_exp = prefix ? 'v%M.%m.%p' : '%M.%m.%p'
  new.version.format(format_exp).freeze
end

.metaString?

Get the version meta-data

Examples:

Get version meta-data

Complish::Version.meta
 #=> 'nightly1234'

Since:

  • 0.2.0-alpha

Version:

  • 1.0


73
74
75
# File 'lib/complish/version.rb', line 73

def self.meta
  new.version.
end

.preString?

Get the version pre-release data

Examples:

Get version pre-release

Complish::Version.pre
 #=> 'alpha'

Since:

  • 0.2.0-alpha

Version:

  • 1.0


63
64
65
# File 'lib/complish/version.rb', line 63

def self.pre
  new.version.prerelease
end

.whole(prefix = false) ⇒ String

Get the whole version number

Examples:

Get the whole Semver version

Complish::Version.whole
 #=> '0.2.0-alpha'

get version whole with prefix

Complish::Version.whole(true)
 #=> 'v0.2.0-alpha'

Since:

  • 0.2.0-alpha

Version:

  • 1.0


37
38
39
40
# File 'lib/complish/version.rb', line 37

def self.whole(prefix = false)
  format_exp = prefix ? 'v%M.%m.%p%s%d' : '%M.%m.%p%s%d'
  new.version.format(format_exp).freeze
end