Skip to content
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

Merged
merged 11 commits into from
Sep 18, 2018
Merged

Add Faker::Json #1156

merged 11 commits into from
Sep 18, 2018

Conversation

the-wendell
Copy link
Contributor

@the-wendell the-wendell commented Feb 26, 2018

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.

@the-wendell the-wendell changed the title Add Faker::Json with tests and documentation JSON Generator Add Faker::Json with tests and documentation Feb 27, 2018
@vbrazo vbrazo force-pushed the master branch 5 times, most recently from a359def to a5d7731 Compare May 22, 2018 21:16
Copy link
Member

@vbrazo vbrazo left a 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?

@the-wendell
Copy link
Contributor Author

My code relies quite heavily on Ruby's eval method which rubocop does not like so I have added an exception to .rubocop.yml

@vbrazo
Copy link
Member

vbrazo commented Jul 19, 2018

Alright, let me test this PR locally and see how it looks.

Copy link
Member

@vbrazo vbrazo left a 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' })
Copy link
Member

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' })

Copy link
Contributor Author

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

Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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.

@vbrazo vbrazo changed the title JSON Generator Add Faker::Json with tests and documentation Add Faker::Json Sep 6, 2018
@vbrazo vbrazo merged commit f01ae29 into faker-ruby:master Sep 18, 2018
davidmorton0 pushed a commit to davidmorton0/faker that referenced this pull request Jul 12, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants