{"id":25238547,"url":"https://github.com/riseshia/serdes","last_synced_at":"2025-10-26T13:30:56.011Z","repository":{"id":275580756,"uuid":"926496937","full_name":"riseshia/serdes","owner":"riseshia","description":"Serdes is a tool for serializing and deserializing class","archived":false,"fork":false,"pushed_at":"2025-02-03T12:58:41.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-03T13:15:31.299Z","etag":null,"topics":["ruby"],"latest_commit_sha":null,"homepage":"","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/riseshia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2025-02-03T11:08:59.000Z","updated_at":"2025-02-03T12:59:11.000Z","dependencies_parsed_at":"2025-02-03T13:15:33.058Z","dependency_job_id":"d4f1827d-3d87-454c-9016-443a42553fd8","html_url":"https://github.com/riseshia/serdes","commit_stats":null,"previous_names":["riseshia/serdes"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riseshia%2Fserdes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riseshia%2Fserdes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riseshia%2Fserdes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riseshia%2Fserdes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/riseshia","download_url":"https://codeload.github.com/riseshia/serdes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238333475,"owners_count":19454602,"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","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":["ruby"],"created_at":"2025-02-11T17:12:19.738Z","updated_at":"2025-10-26T13:30:56.003Z","avatar_url":"https://github.com/riseshia.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Serdes\n\nSerdes is a tool for *ser*ializing and *des*erializing class.\nIt provides:\n\n- general way to serialize and deserialize\n- simple type checking for attributes\n- basic implementation for some class to Hash.\n\n## Installation\n\n```bash\nbundle add serdes\n```\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n```bash\ngem install serdes\n```\n\n## Usage\n\n```ruby\nrequire \"serdes\"\n\nclass User\n  include Serdes\n\n  rename_all_attributes :PascalCase\n\n  attribute :name, String\n  attribute :age, Integer\n  attribute :profile, optional(String)\n  attribute :tags, array(String)\n  attribute :has_pet, Boolean\n  attribute :plan, String, only: [\"free\", \"premium\"]\nend\n\nuser_hash = {\n  \"Name\" =\u003e \"Alice\",\n  \"Age\" =\u003e 20,\n  \"HasPet\" =\u003e true,\n  \"Tags\" =\u003e [\"tag1\", \"tag2\"]\n}\n\nuser = User.from(user_hash)\n\nuser_hash = {\n  \"Name\" =\u003e \"Alice\",\n  \"Age\" =\u003e 20,\n  \"HasPet\" =\u003e true,\n  \"Tags\" =\u003e [\"tag1\", \"tag2\"]\n}\n\nUser.from(user_hash) # =\u003e raise Serdes::TypeError\n```\n\n### API\n\n- `\u003cclass\u003e.from(obj)`: Deserialize object to \u003cclass\u003e instance.\n  - `from` will call `from_\u003cobj.class\u003e` method if it exists. if not, it returns obj as it is.\n- `\u003cclass\u003e#to_hash`: Serialize \u003cclass\u003e instance to Hash.\n  - There is no support for serialization, as only you need to do is just implement `to_\u003cclass\u003e` method where you want.\n\n### Types\n\n`serdes` provides some convenient types for type checking:\n\n- `optional(type)`:  `type` | `nil`\n- `array`: Array of `type`\n\n### Macro\n\n#### Global macro\n\n- `rename_all_attributes`: Rename all attributes when serializing and deserializing.\n  - Supported: `:snake_case`, `:PascalCase`\n- `symbolize_all_keys`: Symbolize all keys when serializing and deserializing Hash, and vice versa.\n\n#### Attribute macro\n\nYou can also use macro for each attribute by specifying 3rd argument of `attribute`.\n\n- `only`: Only allow given values.\n- `skip_serializing`: Skip serializing attribute by setting truthy value. it will ignore `skip_serializing_if`, `skip_serializing_if_nil` when this set.\n- `skip_serializing_if`: Skip serializing if given proc call returns true.\n- `skip_serializing_if_nil`: alias of `skip_serializing_if: -\u003e(v) { v.nil? }`. It will ignore `skip_serializing_if` when this set.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/riseshia/serdes.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friseshia%2Fserdes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Friseshia%2Fserdes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friseshia%2Fserdes/lists"}