Add mappers for synced folders and basis

This commit is contained in:
sophia 2021-12-01 15:03:01 -06:00 committed by Paul Hinze
parent fb5c2dd339
commit 841573194e
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 102 additions and 0 deletions

View File

@ -258,6 +258,7 @@ end
# NOTE: Always directly load mappers so they are automatically registered and
# available. Using autoloading behavior will result in them being unavailable
# until explicitly requested by name
require Vagrant.source_root.join("plugins/commands/serve/mappers/basis.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/box.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/capabilities.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/command.rb").to_s
@ -269,6 +270,7 @@ require Vagrant.source_root.join("plugins/commands/serve/mappers/machine.rb").to
require Vagrant.source_root.join("plugins/commands/serve/mappers/pathname.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/project.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/state_bag.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/synced_folder.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/target.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/target_index.rb").to_s
require Vagrant.source_root.join("plugins/commands/serve/mappers/terminal.rb").to_s

View File

@ -0,0 +1,59 @@
module VagrantPlugins
module CommandServe
class Mappers
class BasisProtoFromSpec < Mapper
def initialize
super(
inputs: [Input.new(type: SDK::FuncSpec::Value) { |arg|
arg.type == "hashicorp.vagrant.sdk.Args.Basis" &&
!arg&.value&.value.nil?
}
],
output: SDK::Args::Basis,
func: method(:converter),
)
end
def converter(fv)
SDK::Args::Basis.decode(fv.value.value)
end
end
# Build a basis client from a proto instance
class BasisFromProto < Mapper
def initialize
inputs = [].tap do |i|
i << Input.new(type: SDK::Args::Basis)
i << Input.new(type: Broker)
i << Input.new(type: Util::Cacher)
end
super(inputs: inputs, output: Client::Basis, func: method(:converter))
end
def converter(proto, broker, cacher)
cid = proto.target.to_s if proto.target.to_s != ""
return cacher[cid] if cid && cacher.registered?(cid)
project = Client::Basis.load(proto, broker: broker)
cacher[cid] = project if cid
project
end
end
# Build a synced folder client from a serialized proto string
class BasisFromString < Mapper
def initialize
inputs = [].tap do |i|
i << Input.new(type: String)
i << Input.new(type: Broker)
end
super(inputs: inputs, output: Client::Basis, func: method(:converter))
end
def converter(proto, broker)
Client::Basis.load(proto, broker: broker)
end
end
end
end
end

View File

@ -0,0 +1,41 @@
module VagrantPlugins
module CommandServe
class Mappers
# Build a synced folder client from a proto instance
class SyncedFolderFromProto < Mapper
def initialize
inputs = [].tap do |i|
i << Input.new(type: SDK::Args::SyncedFolder)
i << Input.new(type: Broker)
i << Input.new(type: Util::Cacher)
end
super(inputs: inputs, output: Client::SyncedFolder, func: method(:converter))
end
def converter(proto, broker, cacher)
cid = proto.target.to_s if proto.target.to_s != ""
return cacher[cid] if cid && cacher.registered?(cid)
project = Client::SyncedFolder.load(proto, broker: broker)
cacher[cid] = project if cid
project
end
end
# Build a synced folder client from a serialized proto string
class SyncedFolderFromString < Mapper
def initialize
inputs = [].tap do |i|
i << Input.new(type: String)
i << Input.new(type: Broker)
end
super(inputs: inputs, output: Client::SyncedFolder, func: method(:converter))
end
def converter(proto, broker)
Client::SyncedFolder.load(proto, broker: broker)
end
end
end
end
end