Fix Type::Booleans leaking through capabilities

We had some cases where calling a capability that returned a boolean was
not getting correctly unpacked, so instead of `true` or `false` the
capability was putting out
`VagrantPlugins::CommandServe::Type::Boolean`.

This may have been happening in _all_ cases where a boolean was returned
from a capability and we just didn't notice it yet because the return
value was always truthy.

These tweaks should help ensure that Ruby types make it out where they
are supposed to be in Args::Direct usage.
This commit is contained in:
Paul Hinze 2022-07-07 11:29:50 -05:00
parent 186824a568
commit 75d900c93b
No known key found for this signature in database
GPG Key ID: 70B94C31D170FB29
2 changed files with 7 additions and 4 deletions

View File

@ -35,15 +35,15 @@ module VagrantPlugins
name: cap_name,
)
)
cb = proc do |name, args|
cb = lambda do |name, args|
result = client.capability(
SDK::Platform::Capability::NamedRequest.new(
name: name,
func_args: args,
)
)
return nil if result.nil?
mapper.map(result.result)
return nil if result.nil? || result.result.nil?
mapper.map(SDK::Args::Direct.new(arguments: [result.result])).arguments.first
end
[spec, cb]
end

View File

@ -373,7 +373,10 @@ end
class Hashicorp::Vagrant::Sdk::Args::Direct
def to_ruby
VagrantPlugins::CommandServe::Type::Direct.new(
arguments: arguments.map(&:to_ruby)
arguments: arguments.map { |arg|
val = arg.to_ruby
val.is_a?(VagrantPlugins::CommandServe::Type) ? val.value : val
}
)
end
end