File: version_gate.rb

package info (click to toggle)
ruby-combustion 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 332 kB
  • sloc: ruby: 628; makefile: 9; sh: 6
file content (35 lines) | stat: -rw-r--r-- 682 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

require "rubygems"

module Combustion
  class VersionGate
    def self.call(name, *constraints)
      new(name).call(*constraints)
    end

    def initialize(name)
      @name = name
    end

    # Using matches_spec? instead of match? because the former returns true
    # even when the spec has an appropriate _pre-release_ version.
    def call(*constraints)
      return false if spec.nil?

      dependency(*constraints).matches_spec?(spec)
    end

    private

    attr_reader :name

    def dependency(*constraints)
      Gem::Dependency.new(name, *constraints)
    end

    def spec
      Gem.loaded_specs.fetch(name, nil)
    end
  end
end