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
|