Adjust wrapper type generated mappers
This commit is contained in:
parent
68ed3ba1d9
commit
af13724f56
@ -6,30 +6,44 @@ module VagrantPlugins
|
||||
Google::Protobuf.constants.grep(/.Value$/).each do |name|
|
||||
value = Google::Protobuf.const_get(name)
|
||||
next if !value.is_a?(Class)
|
||||
if value.instance_methods.include?(:value)
|
||||
type = value.new.value.class
|
||||
elsif value.instance_methods.include?(:values)
|
||||
type = Array
|
||||
elsif value.instance_methods.include?(:fields)
|
||||
type = Hash
|
||||
end
|
||||
type = value.new.respond_to?(:value) ?
|
||||
value.new.value.class :
|
||||
value.new.values.class
|
||||
klass = Class.new(Mapper).class_eval "
|
||||
n = type.name.to_s.split("::").last
|
||||
Class.new(Mapper).class_eval "
|
||||
def initialize
|
||||
super(
|
||||
inputs: [Input.new(type:#{value.name})],
|
||||
inputs: [Input.new(type: #{value.name})],
|
||||
output: #{type.name},
|
||||
func: method(:converter)
|
||||
)
|
||||
end
|
||||
|
||||
def self.name
|
||||
\"#{name}\"
|
||||
'#{name}To#{n}'
|
||||
end
|
||||
|
||||
def to_s
|
||||
'<#{name}To#{n}:' + object_id.to_s + '>'
|
||||
end
|
||||
|
||||
def converter(proto)
|
||||
proto.value
|
||||
if proto.respond_to?(:value)
|
||||
proto.value
|
||||
elsif proto.respond_to?(:values)
|
||||
proto.values.to_a
|
||||
else
|
||||
proto.fields.to_h
|
||||
end
|
||||
end
|
||||
"
|
||||
self.const_set(
|
||||
name,
|
||||
klass
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user