{"id":25714032,"url":"https://github.com/ilyasgaraev/delegate_key","last_synced_at":"2025-08-20T21:08:07.549Z","repository":{"id":62556962,"uuid":"210230191","full_name":"ilyasgaraev/delegate_key","owner":"ilyasgaraev","description":"Create methods which return hash value","archived":false,"fork":false,"pushed_at":"2023-06-21T21:20:25.000Z","size":18,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-09T20:21:37.024Z","etag":null,"topics":["delegate","hash","key","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/ilyasgaraev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2019-09-22T23:56:41.000Z","updated_at":"2025-03-03T08:59:05.000Z","dependencies_parsed_at":"2025-05-01T08:43:23.274Z","dependency_job_id":"a164dc1e-ccbe-4669-9c7c-fd7a2820d1ad","html_url":"https://github.com/ilyasgaraev/delegate_key","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ilyasgaraev/delegate_key","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyasgaraev%2Fdelegate_key","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyasgaraev%2Fdelegate_key/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyasgaraev%2Fdelegate_key/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyasgaraev%2Fdelegate_key/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ilyasgaraev","download_url":"https://codeload.github.com/ilyasgaraev/delegate_key/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyasgaraev%2Fdelegate_key/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271385957,"owners_count":24750509,"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-08-20T02:00:09.606Z","response_time":69,"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":["delegate","hash","key","ruby"],"created_at":"2025-02-25T12:27:53.737Z","updated_at":"2025-08-20T21:08:07.517Z","avatar_url":"https://github.com/ilyasgaraev.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DelegateKey\n\nProvides a `delegate_key` class method to easily create methods which return hash value by key.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'delegate_key'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install delegate_key\n\n## Usage\n\n### Options\n\n- `:to` - specifies the target object;\n\n- `:prefix` - prefixes the new method with the target name or a custom prefix;\n\n- `:private` - if set to true, changes method visibility to private.\n\n`delegate_key` method receives one or more method names (specified as symbols or strings) and the name of the target object via the `:to` option (also a symbol or string).\n\n```ruby\nclass Foo\n  delegate_key :key, to: :hash\n\n  def hash\n    { key: \"value\" }\n  end\nend\n\nFoo.new.key # =\u003e \"value\"\n```\n\nIf hash key is a string, use string as argument:\n\n```ruby\nclass Foo\n  delegate_key \"key\", to: :hash\n\n  def hash\n    { \"key\" =\u003e \"value\" }\n  end\nend\n\nFoo.new.key # =\u003e \"value\"\n\nclass Foo\n  delegate_key :key, to: :hash\n\n  def hash\n    { \"key\" =\u003e \"value\" }\n  end\nend\n\nFoo.new.key # =\u003e nil\n```\n\nMultiple delegates to the same target are allowed:\n\n```ruby\nclass Foo\n  delegate_key :bar, :baz, to: :hash\n\n  def hash\n    { bar: \"value for bar\", baz: \"value for baz\" }\n  end\nend\n\nFoo.new.bar # =\u003e \"value for bar\"\nFoo.new.baz # =\u003e \"value for baz\"\n```\n\nDelegates can optionally be prefixed using the `:prefix` option. If the value is `true`, the delegate methods are prefixed with the name of the object being delegated to.\n\n```ruby\nclass Foo\n  delegate_key :key, to: :hash, prefix: true\n\n  def hash\n    { key: \"value\" }\n  end\nend\n\nFoo.new.hash_key # =\u003e \"value\"\nFoo.new.key # =\u003e NoMethodError: undefined method `key' for #\u003cFoo:0x00007fc2452354b0\u003e\n```\n\nIt is also possible to supply a custom prefix:\n\n```ruby\nclass Foo\n  delegate_key :key, to: :hash, prefix: :custom\n\n  def hash\n    { key: \"value\" }\n  end\nend\n\nFoo.new.custom_key # =\u003e \"value\"\n```\n\nThe delegated methods are public by default. Pass `private: true` to change that.\n\n```ruby\nclass Foo\n  delegate_key :key, to: :hash, private: true\n\n  def hash\n    { key: \"value\" }\n  end\nend\n\nFoo.new.key # =\u003e NoMethodError: private method `key' called for #\u003cFoo:0x00007fc24531dd28\u003e\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ilyasgaraev/delegate_key. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the DelegateKey project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/delegate_key/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filyasgaraev%2Fdelegate_key","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filyasgaraev%2Fdelegate_key","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filyasgaraev%2Fdelegate_key/lists"}