Add mappers for synced folders and basis
This commit is contained in:
parent
fb5c2dd339
commit
841573194e
@ -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
|
||||
|
||||
59
plugins/commands/serve/mappers/basis.rb
Normal file
59
plugins/commands/serve/mappers/basis.rb
Normal 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
|
||||
41
plugins/commands/serve/mappers/synced_folder.rb
Normal file
41
plugins/commands/serve/mappers/synced_folder.rb
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user