{"id":13880454,"url":"https://github.com/svenfuchs/hashr","last_synced_at":"2025-10-11T08:18:45.061Z","repository":{"id":56875972,"uuid":"2093672","full_name":"svenfuchs/hashr","owner":"svenfuchs","description":"Simple Hash extension to make working with nested hashes (e.g. for configuration) easier and less error-prone.","archived":false,"fork":false,"pushed_at":"2017-04-24T16:24:51.000Z","size":58,"stargazers_count":109,"open_issues_count":10,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-11T08:18:44.482Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://github.com/svenfuchs/hashr","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/svenfuchs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-07-23T16:29:11.000Z","updated_at":"2025-02-08T12:40:44.000Z","dependencies_parsed_at":"2022-08-20T22:00:49.383Z","dependency_job_id":null,"html_url":"https://github.com/svenfuchs/hashr","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/svenfuchs/hashr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fhashr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fhashr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fhashr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fhashr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svenfuchs","download_url":"https://codeload.github.com/svenfuchs/hashr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fhashr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006768,"owners_count":26084148,"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-11T02:00:06.511Z","response_time":55,"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-08-06T08:03:02.992Z","updated_at":"2025-10-11T08:18:45.039Z","avatar_url":"https://github.com/svenfuchs.png","language":"Ruby","readme":"[![Build Status](https://secure.travis-ci.org/svenfuchs/hashr.png)](http://travis-ci.org/svenfuchs/hashr)\n\n# Hashr\n\nHashr is a very simple and tiny class which makes using nested hashes for\nconfiguration (and other purposes) easier.\n\nIt supports the following features:\n\n* method read and write access\n* automatic predicate (boolean, i.e. `?`) methods\n* easy defaults\n* indifferent (strings vs symbols) keys\n\n## Usage\n\nDirectly use Hashr instances like this:\n\n```ruby\nconfig = Hashr.new(foo: { bar: 'bar' })\n\nconfig.foo?     # =\u003e true\nconfig.foo      # =\u003e { bar: 'bar' }\n\nconfig.foo.bar? # =\u003e true\nconfig.foo.bar  # =\u003e 'bar'\n\nconfig.foo.bar = 'bar'\nconfig.foo.bar # =\u003e 'bar'\n\nconfig.foo.baz = 'baz'\nconfig.foo.baz # =\u003e 'baz'\n```\n\nHash core methods are not available but assume you mean to look up keys with\nthe same name:\n\n```ruby\nconfig = Hashr.new(count: 1, key: 'key')\nconfig.count # =\u003e 1\nconfig.key   # =\u003e 'key'\n```\n\nIn order to check a hash stored on a certain key you can convert it to a Ruby\nHash:\n\n```ruby\nconfig = Hashr.new(count: 1, key: 'key')\nconfig.to_h.count # =\u003e 2\nconfig.to_h.key   # =\u003e raises ArgumentError: \"wrong number of arguments (0 for 1)\"\n```\n\nMissing keys won't raise an exception but instead behave like Hash access:\n\n```ruby\nconfig = Hashr.new\nconfig.foo? # =\u003e false\nconfig.foo  # =\u003e nil\n```\n\n## Defaults\n\nDefaults can be defined per class:\n\n```ruby\nclass Config \u003c Hashr\n  default boxes: { memory: '1024' }\nend\n\nconfig = Config.new\nconfig.boxes.memory # =\u003e 1024\n```\n\nOr passed to the instance:\n\n```ruby\ndata = {}\ndefaults = { boxes: { memory: '1024' } }\n\nconfig = Hashr.new(data, defaults)\nconfig.boxes.memory # =\u003e 1024\n```\n\n## Environment defaults\n\nHashr includes a simple module that makes it easy to overwrite configuration\ndefaults from environment variables:\n\n```ruby\nclass Config \u003c Hashr\n  extend Hashr::Env\n\n  self.env_namespace = 'foo'\n\n  default boxes: { memory: '1024' }\nend\n```\n\nNow when an environment variable is defined then it will overwrite the default:\n\n```ruby\nENV['FOO_BOXES_MEMORY'] = '2048'\nconfig = Config.new\nconfig.boxes.memory # =\u003e '2048'\n```\n\n## Other libraries\n\nYou also might want to check out OpenStruct and Hashie.\n\n* [OpenStruct](http://ruby-doc.org/stdlib/libdoc/ostruct/rdoc/classes/OpenStruct.html) does less but comes as a Ruby standard library.\n* [Hashie](https://github.com/intridea/hashie) has a bunch of support classes (like `Mash`, `Dash`, `Trash`) which all support different features that you might need.\n\n## License\n\n[MIT License](https://github.com/svenfuchs/hashr/blob/master/MIT-LICENSE)\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvenfuchs%2Fhashr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvenfuchs%2Fhashr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvenfuchs%2Fhashr/lists"}