Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate clear_foo methods for protobuf compiler #1284

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/tapioca/dsl/compilers/protobuf.rb
Original file line number Diff line number Diff line change
@@ -284,6 +284,11 @@ def create_descriptor_method(klass, desc)
return_type: "void",
)

klass.create_method(
"clear_#{field.name}",
return_type: "void",
)

field
end

43 changes: 43 additions & 0 deletions spec/tapioca/dsl/compilers/protobuf_spec.rb
Original file line number Diff line number Diff line change
@@ -60,6 +60,12 @@ class Cart
sig { params(customer_id: T.nilable(Integer), shop_id: T.nilable(Integer)).void }
def initialize(customer_id: nil, shop_id: nil); end

sig { void }
def clear_customer_id; end

sig { void }
def clear_shop_id; end

sig { returns(Integer) }
def customer_id; end

@@ -97,6 +103,9 @@ class Cart
sig { params(events: T.nilable(String)).void }
def initialize(events: nil); end

sig { void }
def clear_events; end

sig { returns(String) }
def events; end

@@ -136,6 +145,9 @@ def cart_item_index; end

sig { params(value: T.nilable(Google::Protobuf::UInt64Value)).void }
def cart_item_index=(value); end

sig { void }
def clear_cart_item_index; end
end
RBI

@@ -171,6 +183,9 @@ class Cart
sig { params(value_type: T.nilable(T.any(Symbol, Integer))).void }
def initialize(value_type: nil); end

sig { void }
def clear_value_type; end

sig { returns(T.any(Symbol, Integer)) }
def value_type; end

@@ -233,6 +248,9 @@ class Cart
sig { params(value_type: T.nilable(T.any(Symbol, Integer))).void }
def initialize(value_type: nil); end

sig { void }
def clear_value_type; end

sig { returns(T.any(Symbol, Integer)) }
def value_type; end

@@ -267,6 +285,12 @@ class Cart
sig { params(customer_ids: T.nilable(T.any(Google::Protobuf::RepeatedField[Integer], T::Array[Integer])), indices: T.nilable(T.any(Google::Protobuf::RepeatedField[Google::Protobuf::UInt64Value], T::Array[Google::Protobuf::UInt64Value]))).void }
def initialize(customer_ids: Google::Protobuf::RepeatedField.new(:int32), indices: Google::Protobuf::RepeatedField.new(:message, Google::Protobuf::UInt64Value)); end

sig { void }
def clear_customer_ids; end

sig { void }
def clear_indices; end

sig { returns(Google::Protobuf::RepeatedField[Integer]) }
def customer_ids; end

@@ -307,6 +331,12 @@ class Cart
sig { params(customers: T.nilable(T.any(Google::Protobuf::Map[String, Integer], T::Hash[String, Integer])), stores: T.nilable(T.any(Google::Protobuf::Map[String, Google::Protobuf::UInt64Value], T::Hash[String, Google::Protobuf::UInt64Value]))).void }
def initialize(customers: Google::Protobuf::Map.new(:string, :int32), stores: Google::Protobuf::Map.new(:string, :message, Google::Protobuf::UInt64Value)); end

sig { void }
def clear_customers; end

sig { void }
def clear_stores; end

sig { returns(Google::Protobuf::Map[String, Integer]) }
def customers; end

@@ -428,6 +458,12 @@ def ShopName; end

sig { params(value: String).void }
def ShopName=(value); end

sig { void }
def clear_ShopID; end

sig { void }
def clear_ShopName; end
end
RBI

@@ -453,6 +489,13 @@ def ShopName=(value); end
rbi_output = rbi_for(:Cart)

assert_includes(rbi_output, indented(<<~RBI, 2))

sig { void }
def clear_email; end

sig { void }
def clear_phone_number; end

sig { returns(T.nilable(Symbol)) }
def contact_info; end
RBI