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 config to get hashes' keys in snake_case #238

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nexxus-vi
Copy link

@nexxus-vi nexxus-vi commented Oct 20, 2023

This PR adds the option to snakify_keys we receive when calling MangoPay endpoints. This allows us to map objects params 1:1 in the db, without transform them to follow ruby's convention. For example:

default:
=> {"Id"=>"206880768", "UserId"=>"206880767", "CreationDate"=>1697803982, "ProcessedDate"=>nil, "Status"=>"VALIDATION_ASKED", "Reason"=>nil, "Message"=>nil, "Ubos"=>[{"Id"=>"206880769", "CreationDate"=>1697803982, "LastName"=>"Doe", "FirstName"=>"John", "Birthday"=>1300186358, "Nationality"=>"FR", "Address"=>{"AddressLine1"=>"6 Parvis Notre-Dame", "AddressLine2"=>"Pl. Jean-Paul II", "City"=>"Paris", "Region"=>"", "PostalCode"=>"75004", "Country"=>"FR"}, "Birthplace"=>{"City"=>"Paris", "Country"=>"FR"}, "IsActive"=>true}]}

snakify_keys = true:
=> {"id"=>"206880772", "user_id"=>"206880771", "creation_date"=>1697803989, "processed_date"=>nil, "status"=>"VALIDATION_ASKED", "reason"=>nil, "message"=>nil, "ubos"=>[{"id"=>"206880773", "creation_date"=>1697803990, "last_name"=>"Doe", "first_name"=>"John", "birthday"=>1300186358, "nationality"=>"FR", "address"=>{"address_line1"=>"6 Parvis Notre-Dame", "address_line2"=>"Pl. Jean-Paul II", "city"=>"Paris", "region"=>"", "postal_code"=>"75004", "country"=>"FR"}, "birthplace"=>{"city"=>"Paris", "country"=>"FR"}, "is_active"=>true}]}

This change requires activesupport, but adding this gem as dependency lead to bump the minimum ruby version to 2.2.2, idk if this can be a problem.
I've added a bunch of tests and everything seems to be working good. Let me know if further explanations or tests are required

This commit introduces a new feature that allows users to configure the response hash keys to be in snake_case instead of CamelCase, following the ruby convention. Adding a dependency from 'activesupport', this increases the minimum ruby version to 2.2.2

The new feature is implemented in a way that it does not break existing functionality. There are also additional tests to ensure the correctness of the new feature.
refactor ubo_spec.rb;
add method to camelize keys.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant