lib/tapioca/dsl/compilers/protobuf.rb in tapioca-0.7.3 vs lib/tapioca/dsl/compilers/protobuf.rb in tapioca-0.8.0
- old
+ new
@@ -81,10 +81,11 @@
create_type_members(klass, "Elem")
elsif constant == Google::Protobuf::Map
create_type_members(klass, "Key", "Value")
else
descriptor = T.let(T.unsafe(constant).descriptor, Google::Protobuf::Descriptor)
+ descriptor.each_oneof { |oneof| create_oneof_method(klass, oneof) }
fields = descriptor.map { |desc| create_descriptor_method(klass, desc) }
fields.sort_by!(&:name)
parameters = fields.map do |field|
create_kw_opt_param(field.name, type: field.init_type, default: field.default)
@@ -213,9 +214,22 @@
parameters: [create_param("value", type: field.type)],
return_type: field.type
)
field
+ end
+
+ sig do
+ params(
+ klass: RBI::Scope,
+ desc: Google::Protobuf::OneofDescriptor
+ ).void
+ end
+ def create_oneof_method(klass, desc)
+ klass.create_method(
+ desc.name,
+ return_type: "T.nilable(Symbol)"
+ )
end
end
end
end
end