Define respond_to? on RecordRef to match method_missing behavior#608
Open
cgunther wants to merge 1 commit intoNetSweet:masterfrom
Open
Define respond_to? on RecordRef to match method_missing behavior#608cgunther wants to merge 1 commit intoNetSweet:masterfrom
respond_to? on RecordRef to match method_missing behavior#608cgunther wants to merge 1 commit intoNetSweet:masterfrom
Conversation
`RecordRef`s often include a name, which allows access via `method_missing` by calling `record_ref.name`, however if no referenced record is assigned, you'll still get a `RecordRef` instance, it just wont have any fields, so `record_ref.name` raised a `NoMethodError`, but if you checked for the field first via `record_ref.respond_to?(:name)`, it'd be falsey regardless of whether the field existed or not. Defining `respond_to?` in good practice alongside `method_missing`. Ideally, `respond_to_missing?` would be used instead, as that enables access to the method like `record_ref.method(:name)`, however I kept with `respond_to?` to match `CustomFieldList`. `CustomRecordRef` also uses `method_missing`, however there's no specs and I'm not familiar with that record, so I left it alone.
32c7342 to
9e74b12
Compare
Contributor
Author
|
CI is failing because of an upstream change in Nori, which can be fixed by #607 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RecordRefs often include a name, which allows access viamethod_missingby callingrecord_ref.name, however if no referenced record is assigned, you'll still get aRecordRefinstance, it just wont have any fields, sorecord_ref.nameraised aNoMethodError, but if you checked for the field first viarecord_ref.respond_to?(:name), it'd be falsey regardless of whether the field existed or not.Defining
respond_to?in good practice alongsidemethod_missing. Ideally,respond_to_missing?would be used instead, as that enables access to the method likerecord_ref.method(:name), however I kept withrespond_to?to matchCustomFieldList.CustomRecordRefalso usesmethod_missing, however there's no specs and I'm not familiar with that record, so I left it alone.