File: utils.rb

package info (click to toggle)
ruby-test-prof 0.12.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 508 kB
  • sloc: ruby: 4,075; makefile: 4
file content (24 lines) | stat: -rw-r--r-- 748 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

module TestProf
  module Utils # :nodoc:
    class << self
      # Verify that loaded gem has correct version
      def verify_gem_version(gem_name, at_least: nil, at_most: nil)
        raise ArgumentError, "Please, provide `at_least` or `at_most` argument" if
          at_least.nil? && at_most.nil?

        spec = Gem.loaded_specs[gem_name]
        version = spec.version if spec
        return false if version.nil?

        supported_version?(version, at_least, at_most)
      end

      def supported_version?(gem_version, at_least, at_most)
        (at_least.nil? || Gem::Version.new(at_least) <= gem_version) &&
          (at_most.nil? || Gem::Version.new(at_most) >= gem_version)
      end
    end
  end
end