Add Class to known types mapper. Indifferent access for hashes.
This commit is contained in:
parent
df3cc08b1f
commit
45b9c48f03
@ -121,11 +121,12 @@ module VagrantPlugins
|
||||
def converter(hash, mapper)
|
||||
begin
|
||||
entries = hash.map do |k, v|
|
||||
next if v.is_a?(Log4r::Logger)
|
||||
SDK::Args::HashEntry.new(
|
||||
key: mapper.map(k, to: Google::Protobuf::Any),
|
||||
value: mapper.map(v, to: Google::Protobuf::Any),
|
||||
)
|
||||
end
|
||||
end.compact
|
||||
SDK::Args::Hash.new(entries: entries)
|
||||
rescue => err
|
||||
logger.error { "hash mapping to proto failed: #{err}" }
|
||||
@ -170,7 +171,7 @@ module VagrantPlugins
|
||||
|
||||
def converter(proto, mapper)
|
||||
begin
|
||||
Hash.new.tap do |result|
|
||||
h = Hash.new.tap do |result|
|
||||
proto.entries.each do |entry|
|
||||
# Convert our key and value to native types
|
||||
k = mapper.map(entry.key)
|
||||
@ -182,6 +183,7 @@ module VagrantPlugins
|
||||
result[k] = v
|
||||
end
|
||||
end
|
||||
Vagrant::Util::HashWithIndifferentAccess.new(h)
|
||||
rescue => err
|
||||
logger.error { "proto mapping to hash failed: #{err}" }
|
||||
raise
|
||||
@ -230,6 +232,68 @@ module VagrantPlugins
|
||||
input.str.to_sym
|
||||
end
|
||||
end
|
||||
|
||||
class ClassToProto < Mapper
|
||||
def initialize
|
||||
super(
|
||||
inputs: [Input.new(type: Class)],
|
||||
output: SDK::Args::Class,
|
||||
func: method(:converter),
|
||||
)
|
||||
end
|
||||
|
||||
def converter(c)
|
||||
SDK::Args::Class.new(name: c.name)
|
||||
end
|
||||
end
|
||||
|
||||
class ClassFromProto < Mapper
|
||||
def initialize
|
||||
super(
|
||||
inputs: [Input.new(type: SDK::Args::Class)],
|
||||
output: Class,
|
||||
func: method(:converter),
|
||||
)
|
||||
end
|
||||
|
||||
def converter(c)
|
||||
if c.name.to_s.empty?
|
||||
c.name = "Vagrant::Config::V2::DummyConfig"
|
||||
# raise "no class name defined for conversion! (value: #{c})"
|
||||
end
|
||||
c.name.split("::").inject(Object) { |memo, name|
|
||||
memo.const_get(name)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
class RangeToProto < Mapper
|
||||
def initialize
|
||||
super(
|
||||
inputs: [Input.new(type: Range)],
|
||||
output: SDK::Args::Range,
|
||||
func: method(:converter),
|
||||
)
|
||||
end
|
||||
|
||||
def converter(r)
|
||||
SDK::Args::Range.new(start: r.first, end: r.last)
|
||||
end
|
||||
end
|
||||
|
||||
class RangeFromProto < Mapper
|
||||
def initialize
|
||||
super(
|
||||
inputs: [Input.new(type: SDK::Args::Range)],
|
||||
output: Range,
|
||||
func: method(:converter),
|
||||
)
|
||||
end
|
||||
|
||||
def converter(r)
|
||||
Range.new(r.start, r.end)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user