Class: Omnibus::SemanticVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/omnibus/semantic_version.rb

Instance Method Summary collapse

Constructor Details

#initialize(version_string) ⇒ SemanticVersion

Returns a new instance of SemanticVersion.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/omnibus/semantic_version.rb', line 22

def initialize(version_string)
  @prefix = if version_string =~ /^v/
              "v"
            else
              ""
            end
  @version = Mixlib::Versioning.parse(version_string.gsub(/^v/, ""))
  if @version.nil?
    raise InvalidVersion, "#{version_string} could not be parsed as a valid version"
  end
end

Instance Method Details

#next_majorObject



48
49
50
51
# File 'lib/omnibus/semantic_version.rb', line 48

def next_major
  s = [version.major + 1, 0, 0].join(".")
  self.class.new("#{prefix}#{s}")
end

#next_minorObject



43
44
45
46
# File 'lib/omnibus/semantic_version.rb', line 43

def next_minor
  s = [version.major, version.minor + 1, 0].join(".")
  self.class.new("#{prefix}#{s}")
end

#next_patchObject



38
39
40
41
# File 'lib/omnibus/semantic_version.rb', line 38

def next_patch
  s = [version.major, version.minor, version.patch + 1].join(".")
  self.class.new("#{prefix}#{s}")
end

#to_sObject



34
35
36
# File 'lib/omnibus/semantic_version.rb', line 34

def to_s
  "#{prefix}#{version}"
end