{"id":31696699,"url":"https://github.com/joaquinco/hash-nestizy","last_synced_at":"2026-05-14T22:48:59.941Z","repository":{"id":42514032,"uuid":"392450447","full_name":"joaquinco/hash-nestizy","owner":"joaquinco","description":"Nestizy a hash by spliting keys by some character","archived":false,"fork":false,"pushed_at":"2024-09-30T20:41:54.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-09T02:41:28.794Z","etag":null,"topics":["rails","rails-api","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/hash_nestizy","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joaquinco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-08-03T20:42:45.000Z","updated_at":"2024-10-10T14:24:19.000Z","dependencies_parsed_at":"2024-09-09T21:10:12.159Z","dependency_job_id":"fbd39163-c8d1-4429-920c-80673369dc3e","html_url":"https://github.com/joaquinco/hash-nestizy","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"e8f1c8a13693e3811100e155a1d29196986a3d33"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/joaquinco/hash-nestizy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaquinco%2Fhash-nestizy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaquinco%2Fhash-nestizy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaquinco%2Fhash-nestizy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaquinco%2Fhash-nestizy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joaquinco","download_url":"https://codeload.github.com/joaquinco/hash-nestizy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaquinco%2Fhash-nestizy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280706841,"owners_count":26376990,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-23T02:00:06.710Z","response_time":142,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rails","rails-api","ruby"],"created_at":"2025-10-08T17:15:18.319Z","updated_at":"2025-10-23T22:57:41.265Z","avatar_url":"https://github.com/joaquinco.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![ruby-ci](https://github.com/joaquinco/hash-nestizy/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/joaquinco/hash-nestizy/actions/workflows/ci.yml)\n\nHash Nestizy\n============\n\nConvert a flat hash representation to a nested one. Specifically useful to return easily to handle rails `ActiveModel::Error` in API mode.\n\nSplits `Symbol` and `String` keys but converting them to stirng and using\n`String#split` method.\n\nTested on Ruby 2.5 and newer but probably works on older versions.\n\n## Examples\n\n```ruby\n\u003e\u003e\u003e require 'hash_nestizy'\n=\u003e true\n\u003e\u003e\u003e errors = { 'name' =\u003e 'is required', 'role.name' =\u003e 'max be longer than 5' }\n=\u003e {\"name\"=\u003e\"is required\", \"role.name\"=\u003e\"max be longer than 5\"}\n\u003e\u003e\u003e HashNestizy.to_nested(errors)\n=\u003e {\"name\"=\u003e\"is required\", \"role\"=\u003e{\"name\"=\u003e\"max be longer than 5\"}}\n```\n\nThere's also a handy method to patch it to the `Hash` class.\n\n```ruby\n\u003e\u003e\u003e HashNestizy.patch_hash!\n=\u003e Hash\n\u003e\u003e\u003e { 'name' =\u003e 'is required', 'role.name' =\u003e 'max be longer than 5' }.nestizy\n=\u003e {\"name\"=\u003e\"is required\", \"role\"=\u003e{\"name\"=\u003e\"max be longer than 5\"}}\n```\n\nYou can use it to render `ActiveModel::Error` instances on rails APIs as follow:\n\n```ruby\nclass ApiController \u003c ApplicationController\n  rescue_from ActiveRecord::RecordInvalid, with: :record_invalid\n\n  def record_invalid(ex)\n    render json: HashNestizy.to_nested(ex.record.errors.to_hash), status: :bad_request\n  end\nend\n```\n\n### Beware of key collisions\n\nUnexpected behaviour might occur on key conflicts. There's no reasonable way\nto handle this on a case that fits all use cases.\n\n```ruby\n\u003e\u003e\u003e data = {'role' =\u003e 'admin', 'role.name' =\u003e 'Administrator'}\n=\u003e {\"role\"=\u003e\"admin\", \"role.name\"=\u003e\"Administrator\"}\n\u003e\u003e\u003e HashNestizy.to_nested(data)\n=\u003e {\"role\"=\u003e\"admin\"}\n```\n\nYou can specify an iterator of `[key, value]` pairs and use the `override: bool` parameter\nto handle key conflicts correctly:\n\n```ruby\n\u003e\u003e\u003e data = [['role', 'admin'], ['role.name', 'Administrator']]\n=\u003e [[\"role\", \"admin\"], [\"role.name\", \"Administrator\"]]\n\u003e\u003e\u003e HashNestizy.to_nested(data, override: true)\n=\u003e {\"role\"=\u003e{\"name\": \"Administrator\"}}\n\n```\n\n## Changelog\n\n- 0.0.3: Initial release.\n- 0.1.0: Handle conflicts correctly.\n- 0.2.0: Cleaner implementaiton.\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoaquinco%2Fhash-nestizy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoaquinco%2Fhash-nestizy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoaquinco%2Fhash-nestizy/lists"}