Sha256: 3be925b01ed3b0fd355ae77438579e2d9e4fb00dd20c28f54fe754b242ec29fa

Contents?: true

Size: 986 Bytes

Versions: 19

Compression:

Stored size: 986 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]
      rescue Exception
        []
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
virtualbox-0.9.2 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.9.1 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.9.0 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.8.6 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.8.5 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.8.4 lib/virtualbox/abstract_model/version_matcher.rb
velir_virtualbox-0.8.4 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.8.3 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.8.2 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.8.1 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.8.0 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.7.9 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.7.8 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.7.7 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.7.6 lib/virtualbox/abstract_model/version_matcher.rb
bbrowning-virtualbox-0.7.6.dev lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.7.5 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.7.4 lib/virtualbox/abstract_model/version_matcher.rb
virtualbox-0.7.3 lib/virtualbox/abstract_model/version_matcher.rb