core: BoxMetadata#version can constrain by providers
This commit is contained in:
parent
7d44cd61c9
commit
80194cde35
|
@ -45,15 +45,19 @@ module Vagrant
|
|||
# be a constraint.
|
||||
# @return [Version] The matching version or nil if a matching
|
||||
# version was not found.
|
||||
def version(version)
|
||||
def version(version, **opts)
|
||||
requirements = version.split(",").map do |v|
|
||||
Gem::Requirement.new(v.strip)
|
||||
end
|
||||
|
||||
providers = nil
|
||||
providers = Array(opts[:provider]) if opts[:provider]
|
||||
|
||||
@version_map.keys.sort.reverse.each do |v|
|
||||
if requirements.all? { |r| r.satisfied_by?(v) }
|
||||
return Version.new(@version_map[v])
|
||||
end
|
||||
next if !requirements.all? { |r| r.satisfied_by?(v) }
|
||||
version = Version.new(@version_map[v])
|
||||
next if (providers & version.providers).empty? if providers
|
||||
return version
|
||||
end
|
||||
|
||||
nil
|
||||
|
|
|
@ -12,13 +12,24 @@ describe Vagrant::BoxMetadata do
|
|||
"description": "bar",
|
||||
"versions": [
|
||||
{
|
||||
"version": "1.0.0"
|
||||
"version": "1.0.0",
|
||||
"providers": [
|
||||
{ "name": "virtualbox" },
|
||||
{ "name": "vmware" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.1.5"
|
||||
"version": "1.1.5",
|
||||
"providers": [
|
||||
{ "name": "virtualbox" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.1.0"
|
||||
"version": "1.1.0",
|
||||
"providers": [
|
||||
{ "name": "virtualbox" },
|
||||
{ "name": "vmware" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -64,6 +75,13 @@ describe Vagrant::BoxMetadata do
|
|||
expect(result).to be_kind_of(Vagrant::BoxMetadata::Version)
|
||||
expect(result.version).to eq("1.0.0")
|
||||
end
|
||||
|
||||
it "matches the constraint that has the given provider" do
|
||||
result = subject.version(">= 0", provider: "vmware")
|
||||
expect(result).to_not be_nil
|
||||
expect(result).to be_kind_of(Vagrant::BoxMetadata::Version)
|
||||
expect(result.version).to eq("1.1.0")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#versions" do
|
||||
|
|
Loading…
Reference in New Issue