Sha256: b9944d0ae70b03b38f8592933d45f8bf44c1299607b5c233afe76635d0953711

Contents?: true

Size: 1.47 KB

Versions: 22

Compression:

Stored size: 1.47 KB

Contents

#
# Copyright 2015-2018 Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require "mixlib/versioning"

module Omnibus
  class SemanticVersion

    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

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

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

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

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

    private

    attr_reader :prefix, :version
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
omnibus-9.0.24 lib/omnibus/semantic_version.rb
omnibus-9.0.23 lib/omnibus/semantic_version.rb
omnibus-9.0.22 lib/omnibus/semantic_version.rb
omnibus-9.0.17 lib/omnibus/semantic_version.rb
omnibus-9.0.12 lib/omnibus/semantic_version.rb
omnibus-9.0.11 lib/omnibus/semantic_version.rb
omnibus-9.0.8 lib/omnibus/semantic_version.rb
omnibus-8.3.2 lib/omnibus/semantic_version.rb
omnibus-8.2.2 lib/omnibus/semantic_version.rb
omnibus-8.1.15 lib/omnibus/semantic_version.rb
omnibus-8.0.15 lib/omnibus/semantic_version.rb
omnibus-8.0.9 lib/omnibus/semantic_version.rb
omnibus-7.0.34 lib/omnibus/semantic_version.rb
omnibus-7.0.13 lib/omnibus/semantic_version.rb
omnibus-7.0.12 lib/omnibus/semantic_version.rb
omnibus-6.1.9 lib/omnibus/semantic_version.rb
omnibus-6.1.7 lib/omnibus/semantic_version.rb
omnibus-6.1.4 lib/omnibus/semantic_version.rb
omnibus-6.0.30 lib/omnibus/semantic_version.rb
omnibus-6.0.25 lib/omnibus/semantic_version.rb