Fix relationships with &:proc shorthands - #58
Conversation
|
@attilahorvath apologies for a bit of delay in reviewing this... Before we merge this, I'd like us to review all the parts where we work with procs and use the new internal API method you suggested Functionality aside, let's document this method properly and remove extra tests from #59 once we update it to use this API call. I'm ok if you want to merge this one first and update the #59 later. Let me know what you think... Thanks in advance! 🙇♂️ |
|
Sounds good. @attilahorvath may I ask you to provide the docstrings for the new method, consider using the YARD format. I'll merge it as soon as you do that. Thanks! |
|
Okay, I've given it some more thought and came up with the following. I have a small helper method that works with either This method will be needed in multiple source files so I put it in a new If you're happy with this, I'll update all other usages of proc calls across the gem to use this method so they won't have similar issues in the future. |
|
@attilahorvath this looks good, let's move forward with this if you have time! 🙇♂️ |
|
🙇♂️ @attilahorvath |
What is the current behavior?
If a define a relationship with a
&:procshorthand, such as:The serialization fails with
ArgumentError: wrong number of arguments (given 1, expected 0).However, the same thing would have worked as expected had I used a full
do .. endblock here.What is the new behavior?
This change fixes this behavior by doing the same arity check as it's been done already for attributes in Scalar.
It would be nice to extract this bit of code somewhere instead of being duplicated here but I couldn't really find a nice place for that as they don't share a common superclass or anything like that. I can refactor this if anyone has a better idea.
Checklist
Please make sure the following requirements are complete:
features)