{"id":19343517,"url":"https://github.com/hex0cter/hash2obj","last_synced_at":"2025-10-13T15:36:27.917Z","repository":{"id":56875916,"uuid":"61142988","full_name":"hex0cter/hash2obj","owner":"hex0cter","description":"Ruby gem that applies a hash into a Ruby object and return another instance of the same class using the data in the hash.","archived":false,"fork":false,"pushed_at":"2016-11-18T09:32:13.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-18T01:28:56.417Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/hash2obj","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/hex0cter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-14T17:39:10.000Z","updated_at":"2016-11-18T09:32:14.000Z","dependencies_parsed_at":"2022-08-20T11:30:42.769Z","dependency_job_id":null,"html_url":"https://github.com/hex0cter/hash2obj","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/hex0cter/hash2obj","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hex0cter%2Fhash2obj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hex0cter%2Fhash2obj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hex0cter%2Fhash2obj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hex0cter%2Fhash2obj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hex0cter","download_url":"https://codeload.github.com/hex0cter/hash2obj/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hex0cter%2Fhash2obj/sbom","scorecard":{"id":462708,"data":{"date":"2025-08-11","repo":{"name":"github.com/hex0cter/hash2obj","commit":"5c941e018013a29a7d9364e86e4606df57078f13"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/5 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: MIT License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-19T11:34:37.093Z","repository_id":56875916,"created_at":"2025-08-19T11:34:37.094Z","updated_at":"2025-08-19T11:34:37.094Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278838484,"owners_count":26054731,"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-07T02:00:06.786Z","response_time":59,"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":[],"created_at":"2024-11-10T03:38:34.127Z","updated_at":"2025-10-13T15:36:27.902Z","avatar_url":"https://github.com/hex0cter.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The Hash2Obj gem for Ruby\n\n[![Gem Version](https://badge.fury.io/rb/hash2obj.svg)](https://badge.fury.io/rb/hash2obj)\n[![Build Status](https://travis-ci.org/hex0cter/hash2obj.svg?branch=master)](https://travis-ci.org/hex0cter/hash2obj)\n\nHash2Obj (formerly known as clavatar) is a ruby gem that converts a hash into a Ruby object.\n\nDuring the web development, it is common to transfer json between the browser and the server. When the json from the\nbrowser presents an object, you might need to convert it back into a Ruby object on the server side.\n\nNormally the class you want to convert to has to provide a method or constructor that takes a hash as argument. In that\nway you will have to implement the same interface for all the classes.\n\nHash2Obj provides another solution for this. When you want to convert a json (hash) into the object, you just need to\nprovide an existing instance of the same class. For example,\n\nWhen you call\n\n```ruby\nHash2Obj.cast(hash, object)\n```\n\nhash2obj will first inspect all the internal data of object and find out which are writable (for instance,\nattr_accessor, attr_writer, etc.) and which are not (for instance, attr_reader, private members, etc).\n\nFor those that are not writable, hash2obj attempts to call its constructor using the information provided by the hash.\nAt the moment hash2obj supports the class constructor in any of the following forms:\n\n```ruby\nclass A\n    def initialize([param_1[, param_2[, ...]]] [param_x:[, param_y:[, ...]]] [**args])\n        ...\n    end\nend\n```\n\nOnce a new instance is created, hash2obj just copies all the other accessible data to the new instance.\n\nBelow is an example of how to use hash2obj:\n\n```ruby\nrequire 'hash2obj'\n\nmodule TestModule\n  class MyKlass\n    attr_reader :b1\n    attr_reader :b2\n    attr_reader :b3\n    attr_reader :b4\n    attr_writer :b5\n    attr_writer :b6\n\n    def initialize(b1, b2 = 2, b3:, b4: 4, **args)\n      @b1 = b1\n      @b2 = b2\n      @b3 = b3\n      @b4 = b4\n      @b5 = args.fetch :b5, 0\n      @b6 = args.fetch :b6, 0\n    end\n\n    def get_attr_b5\n      @b5\n    end\n\n    def get_attr_b6\n      @b6\n    end\n  end\nend\n\n\nold_obj = TestModule::MyKlass.new(1, b3: 3, b5:5)\nold_obj.b6 = 6\nold_obj.inspect \n# =\u003e \"#\u003cMyModule::MyKlass:0xxxxxxx @b1=1, @b2=2, @b3=3, @b4=4, @b5=5, @b6=6\u003e\"\n\nnew_obj = Hash2Obj.cast({b1: 11, b2: 12, b3: 13, b4: 14, b5: 15, b6: 16}, old_obj)\nnew_obj.inspect \n# =\u003e \"#\u003cMyModule::MyKlass:0xxxxxxx @b1=11, @b2=12, @b3=13, @b4=14, @b5=15, @b6=16\u003e\"\n```\n\n## How to install?\n\nFrom a terminal run\n\n```bash\n  gem install hash2obj\n```\n\nor add the following code into your Gemfiles:\n\n```ruby\n  gem 'hash2obj'\n```\n\n## License\n\nThis code is free to use under the terms of the MIT license.\n\n## Contribution\n\nYou are more than welcome to raise any issues [here](https://github.com/hex0cter/hash2obj/issues), or create a Pull Request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhex0cter%2Fhash2obj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhex0cter%2Fhash2obj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhex0cter%2Fhash2obj/lists"}