You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm noticing that if I assign an object that inherits from the ruby class which is created from the protocol definition, it is downcast, and I don't see any particular reason why. For example
Lets say I have the following classes. (The reason I'm doing this is I'm injecting a ton of validations into the new class; the other way to do this is to not have Corp::Location inherit from the proto-based ruby object but instead just serialize into it.... such as Corp::Location#to_proto calls Corp::WireDefinition::Location.new(self.to_hash).to_proto... thoughts on approach?)
Anyway, I digress a bit... check this out:
moduleCorpclassLocation < Corp::WireDefinition::Location#a ton of validationsendendmoduleCorpclassBusiness < Corp::WireDefinition::Business# includes an array of Locationsendend
if I run the following, on assignment, the Corp::Location instance is downcast. This is problematic if I have methods within Corp::Location that I need to call later (such as running validations).
business=Corp::Business.newbusiness.locations=[Corp.Location.new,Corp.Location.new]business.locations.first.is_a?(Corp.Location)# => false; it is a Corp::WireDefinition::Location
I don't understand why it is creating a new object here, downcasting it in the process, and git blame doesn't shed any light as to why this logic is here. Thoughts? Would it be ok if I submit a PR that rips this out?
The text was updated successfully, but these errors were encountered:
hello,
I'm noticing that if I assign an object that inherits from the ruby class which is created from the protocol definition, it is downcast, and I don't see any particular reason why. For example
Lets say I have the following classes. (The reason I'm doing this is I'm injecting a ton of validations into the new class; the other way to do this is to not have
Corp::Location
inherit from the proto-based ruby object but instead just serialize into it.... such asCorp::Location#to_proto
callsCorp::WireDefinition::Location.new(self.to_hash).to_proto
... thoughts on approach?)Anyway, I digress a bit... check this out:
if I run the following, on assignment, the
Corp::Location
instance is downcast. This is problematic if I have methods withinCorp::Location
that I need to call later (such as running validations).The culprit is this line: https://github.com/localshred/protobuf/blob/master/lib/protobuf/field/field_array.rb#L70
I don't understand why it is creating a new object here, downcasting it in the process, and git blame doesn't shed any light as to why this logic is here. Thoughts? Would it be ok if I submit a PR that rips this out?
The text was updated successfully, but these errors were encountered: