-
Notifications
You must be signed in to change notification settings - Fork 29
[Ruby] Extended JSON #168
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
[Ruby] Extended JSON #168
Conversation
✅ Deploy Preview for docs-ruby ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🔄 Deploy Preview for docs-ruby processing
|
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.
Looks good so far! I left some minor comments
You can write an Extended JSON string from a hash by using the | ||
``as_extended_json()`` method. Using the Ruby ``map{}`` method, you can create | ||
an Extended JSON string from an array of hashes. By default, this method returns | ||
the Extended JSON string in canonical format, but you can specify relaxed or |
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.
S: I was a little confused by this description of both the as_extended_json()
method and map{}
, and which one "this method" refers to. I think you can just describe as_extended_json()
in this intro section, then talk about map
further down:
You can write an Extended JSON string from a hash by using the | |
``as_extended_json()`` method. Using the Ruby ``map{}`` method, you can create | |
an Extended JSON string from an array of hashes. By default, this method returns | |
the Extended JSON string in canonical format, but you can specify relaxed or | |
You can write an Extended JSON string from a hash by using the | |
``as_extended_json()`` method. By default, this method returns | |
the Extended JSON string in canonical format, but you can specify relaxed or |
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.
Good call out. I moved the map
description to the example intro below.
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.
LGTM with a couple nits!
json_array_canonical = hash_array.map(&:as_extended_json) | ||
json_array_relaxed = hash_array.map{ |hash| hash.as_extended_json(mode: :relaxed) } | ||
json_array_legacy = hash_array.map{ |hash| hash.as_extended_json(mode: :legacy) } |
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.
Note that the bson library also defines Array#as_extended_json
, which does pretty much what you have (mapping the array so each element has the method invoked on it as well).
(See https://github.com/mongodb/bson-ruby/blob/master/lib/bson/array.rb#L104-L108)
json_array_canonical = hash_array.map(&:as_extended_json) | |
json_array_relaxed = hash_array.map{ |hash| hash.as_extended_json(mode: :relaxed) } | |
json_array_legacy = hash_array.map{ |hash| hash.as_extended_json(mode: :legacy) } | |
json_array_canonical = hash_array.as_extended_json | |
json_array_relaxed = hash_array.as_extended_json(mode: :relaxed) | |
json_array_legacy = hash_array.as_extended_json(mode: :legacy) |
and legacy formats. It calls the ``as_extended_json()`` method from inside a | ||
Ruby ``map{}`` block to create the Extended JSON string from an array of hashes: |
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.
As noted in a later comment, you can invoke #as_extended_json
directly on an array instance.
and legacy formats. It calls the ``as_extended_json()`` method from inside a | |
Ruby ``map{}`` block to create the Extended JSON string from an array of hashes: | |
and legacy formats. It calls the ``#as_extended_json`` method on an array to create the | |
Extended JSON string from an array of hashes: |
Also, Ruby convention refers to instance methods as #method_name
, rather than method_name()
.
5a4773f
to
5233654
Compare
* DOCSP-51932: v2.21.2 patch release (mongodb#163) * shared content * write * link formatting * link formatting * NR feedback * NR feedback * JB feedback * rephrase * remove extra change --------- Co-authored-by: Nora Reidy <nora.reidy@mongodb.com>
* DOCSP-51932: v2.21.2 patch release (#163) * change TOC name (#165) * add a redirect (#169) * [Ruby] TOC Reorg (#160) * toc reorg * tweaks * DOCSP-51415 Add causal consistency section (#161) * [Ruby] CRUD - Upsert (#164) * DOCSP-51932: v2.21.2 patch release (#163) * add upsert section * reference * LM feedback * checkout snooty --------- Co-authored-by: Nora Reidy <nora.reidy@mongodb.com> * DOCSP-51416 Network Compression (#162) * [Ruby] Load Balancers (#166) * DOCSP-51932: v2.21.2 patch release (#163) * client option * undo snooty change * formatting * formatting * DR feedback --------- Co-authored-by: Nora Reidy <nora.reidy@mongodb.com> * [Ruby] Extended JSON (#168) * DOCSP-51932: v2.21.2 patch release (#163) * shared content * write * link formatting * link formatting * NR feedback * NR feedback * JB feedback * rephrase * remove extra change --------- Co-authored-by: Nora Reidy <nora.reidy@mongodb.com> --------- Co-authored-by: Nora Reidy <nora.reidy@mongodb.com> Co-authored-by: shuangela <angela.shu@mongodb.com> Co-authored-by: Jordan Smith <45415425+jordan-smith721@users.noreply.github.com>
Pull Request Info
PR Reviewing Guidelines
JIRA - https://jira.mongodb.org/browse/DOCSP-51421
Staging Links
Self-Review Checklist