-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add Faker::Json #1156
Add Faker::Json #1156
Conversation
a359def
to
a5d7731
Compare
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.
Could you please rebase/update your branch with master and fix the rubocop
violations?
add expetions to rubocop.yml
My code relies quite heavily on Ruby's |
Alright, let me test this PR locally and see how it looks. |
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.
Sorry for the delay. Nice contribution. I really enjoyed it 🥇
require 'json' | ||
|
||
class << self | ||
def shallow_json(width = 3, options = { key: 'Name.first_name', value: 'Name.first_name' }) |
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.
Could we convert to keyword arguments?
def shallow_json(width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
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.
Sure, I should have some time this weekend to make the change
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 think we can skip this review for now because we have an open PR that plans to convert these parameters to keyword arguments #605. This PR should be merged in faker v2.0. I think the contributor will need to rebase and fix several other methods and your module will be included, so we don't need to do this change right now.
doc/json.md
Outdated
returned JSON string is equal to the width_int. | ||
|
||
`options_hash = {key: Class.method, value: Class.method}` where Class is | ||
any class in the Faker gem. For example if you wanted random names for keys |
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 think it should be if you want random names for keys
instead of wanted
?
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 catch! I will fix it.
* Add Faker::Json with tests and documentation * Fix rubo cop erros add expetions to rubocop.yml * Fix rubocop erros in test_faker_json.rb * Update json.md * Update json.rb * Update test_faker_json.rb * Update test_faker_json.rb * Update json.rb * Update .rubocop.yml
As requested under issues #1126
Faker::Json returns a JSON string of a specified size with keys and values generated from a specified Faker Class. ex: You could generate a JSON with 5 key value pairs where the keys are random names and the values are random quotes.
It is also possible to add depth indefinitely to a given JSON.