Sha256: aadd71a7668270e6856dad753e3c50e23c545588d74550f0bc0c93424abf8dda

Contents?: true

Size: 952 Bytes

Versions: 1

Compression:

Stored size: 952 Bytes

Contents

module VirtualBox
  class AbstractModel
    module VersionMatcher
      # Asserts that two versions match. Otherwise raises an
      # exception.
      def assert_version_match(req, cur)
        if !version_match?(req, cur)
          message = "Required version: #{req}; Current: #{cur}"
          raise Exceptions::UnsupportedVersionException.new(message)
        end
      end

      # Checks if a given version requirement matches the current
      # version.
      #
      # @return [Boolean]
      def version_match?(requirement, current)
        split_version(requirement) == split_version(current)
      end

      # Splits a version string into a two-item array with the parts
      # of the version, respectively. If the version has more than two
      # parts, the rest are ignored.
      #
      # @param [String] version
      # @return [Array]
      def split_version(version)
        version.split(/\./)[0,2]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
virtualbox-0.7.2 lib/virtualbox/abstract_model/version_matcher.rb