-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Added support for mapping YAML nodes not specified in properties #4411
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
73627b4
Added support for mapping YAML nodes not specified in properties
aaronbronow af9520f
forgot to format
aaronbronow c30e25c
Added macro exception when extra property name collides with mapped p…
aaronbronow ad4a54c
Added test for extra attribute mapping in YAML parser
aaronbronow f8c23b9
Removed unneeded local variable assignment
aaronbronow 5d4a021
Added extra mapping to to_yaml
aaronbronow f98ddb5
forgot to format
aaronbronow 09ed51e
Merge remote-tracking branch 'upstream/master'
aaronbronow d63aa62
Added support for extras in JSON mapping
aaronbronow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest using
%fresh variables.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but why not just call .to_yaml on the @ instance variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
@{{extra.id}}exists, then it is not nillable so you could call@{{extra.id}}.to_yaml(...directly. For memory footprint I would suggest to let it be lazy initialized / nilable. But for the use case, if the user expect to have some extras, maybe is good enough to eagerly create a and instance for@{{extra.id}}.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this implementation extra is nil unless the user has set it and passed it in as an argument to the
mapping(...)macro. Because the macro checks for existence of extra before emitting code,@{{extra.id}}won't exist at all if the user is not using extras. If extra does exist then@{{extra.id}}will always get initialized as aHash(String, ::YAML::Any)If I'm understanding this correctly, the only problem with trying to call
@{{extra.id}}.to_yaml(...would be if@{{extra.id}}is nil at the time of executing this block and that's impossible. I hope I'm understanding correctly 😄