{"id":15405197,"url":"https://github.com/fnando/glob","last_synced_at":"2025-04-17T00:51:46.989Z","repository":{"id":36523307,"uuid":"228157253","full_name":"fnando/glob","owner":"fnando","description":"Create a list of hash paths that match a given pattern. You can also generate a hash with only the matching paths.","archived":false,"fork":false,"pushed_at":"2024-01-18T11:44:08.000Z","size":70,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-26T12:02:59.964Z","etag":null,"topics":["hash","match","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/fnando.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["fnando"],"custom":["https://paypal.me/nandovieira/🍕"]}},"created_at":"2019-12-15T09:10:03.000Z","updated_at":"2023-03-08T16:06:30.000Z","dependencies_parsed_at":"2024-10-01T16:15:27.776Z","dependency_job_id":"0eaca330-d4df-48d1-bc73-742d6ebef26a","html_url":"https://github.com/fnando/glob","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":0.3548387096774194,"last_synced_commit":"3e010175d71c13cf836664b1d49b65965d38a55c"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fglob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fglob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fglob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fglob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/glob/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249294908,"owners_count":21246009,"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":["hash","match","ruby"],"created_at":"2024-10-01T16:15:24.381Z","updated_at":"2025-04-17T00:51:46.972Z","avatar_url":"https://github.com/fnando.png","language":"Ruby","funding_links":["https://github.com/sponsors/fnando","https://paypal.me/nandovieira/🍕"],"categories":[],"sub_categories":[],"readme":"# glob\n\n[![Tests](https://github.com/fnando/glob/workflows/ruby-tests/badge.svg)](https://github.com/fnando/glob)\n[![Code Climate](https://codeclimate.com/github/fnando/glob/badges/gpa.svg)](https://codeclimate.com/github/fnando/glob)\n[![Gem](https://img.shields.io/gem/v/glob.svg)](https://rubygems.org/gems/glob)\n[![Gem](https://img.shields.io/gem/dt/glob.svg)](https://rubygems.org/gems/glob)\n\nCreate a list of hash paths that match a given pattern. You can also generate a\nhash with only the matching paths.\n\n## Installation\n\n```bash\ngem install glob\n```\n\nOr add the following line to your project's Gemfile:\n\n```ruby\ngem \"glob\"\n```\n\n## Usage\n\nThere are two types of paths: `include` and `exclude`.\n\n- The `include` path adds that node to the new hash.\n- The `exclude` path is the one started by `!`, and will prevent that path from\n  being added.\n\nRules may also have groups. Let's say you want to target `en.*` and `pt.*`; you\ncase set `{en,pt}.*` rather than having two separate rules.\n\nThe latest rules have more precedence; that means that if you have the rule\n`*.messages.*`, then add a following rule as `!*.messages.bye`, all\n`*.messages.*` but `*.messages.bye` will be included.\n\n```ruby\nglob = Glob.new(\n  site: {\n    settings: {\n      name: \"Site name\",\n      url: \"https://example.com\"\n    }\n  },\n  user: {\n    settings: {\n      name: \"User name\"\n    }\n  }\n)\n\nglob \u003c\u003c \"*.settings.*\"\n\nglob.paths\n#=\u003e [\"site.settings.name\", \"site.settings.url\", \"user.settings.name\"]\n\nglob.to_h\n#=\u003e {\n#=\u003e   site: {\n#=\u003e     settings: {\n#=\u003e       name: \"Site name\"\n#=\u003e     }\n#=\u003e   },\n#=\u003e   user: {\n#=\u003e     settings: {\n#=\u003e       name: \"User name\"\n#=\u003e     }\n#=\u003e   }\n#=\u003e }\n```\n\nNotice that the return result will have symbolized keys.\n\nIf the key contain dots, then the result will use `\\\\.` as the escape sequence.\nSimilarly, you need to escape keys with dots when filtering results.\n\n```ruby\nglob = Glob.new(\n  formats: {\n    \".txt\" =\u003e \"Text\",\n    \".json\" =\u003e \"JSON\",\n    \".rb\" =\u003e \"Ruby\"\n  }\n)\n\nglob \u003c\u003c \"*\"\n\nglob.paths\n#=\u003e [\"formats.\\\\.json\", \"formats.\\\\.rb\", \"formats.\\\\.txt\"]\n\nglob.to_h\n#=\u003e {:formats=\u003e{:\".json\"=\u003e\"JSON\", :\".rb\"=\u003e\"Ruby\", :\".txt\"=\u003e\"Text\"}}\n\n# Remove all existing matchers\nglob.matchers.clear\n\nglob \u003c\u003c \"formats.\\\\.rb\"\n\nglob.paths\n#=\u003e [\"formats.\\\\.rb\"]\n\nglob.to_h\n#=\u003e {:formats=\u003e{:\".rb\"=\u003e\"Ruby\"}}\n```\n\nYou can set new keys by using `.set(path, value)`:\n\n```ruby\nglob = Glob.new\nglob \u003c\u003c \"*\"\nglob.set \"a.b.c\", \"hello\"\n\nglob.to_h\n#=\u003e {:a=\u003e{:b=\u003e{:c=\u003e\"hello\"}}}\n\nglob.paths\n#=\u003e [\"a.b.c\"]\n\n# The non-hash value will be replaced in case the new path overlaps it\nglob.set \"a.b.c.d.e\", \"hello\"\n\nglob.to_h\n#=\u003e {:a=\u003e{:b=\u003e{:c=\u003e{:d=\u003e{:e=\u003e\"hello\"}}}}}\n\nglob.paths\n#=\u003e [\"a.b.c.d.e\"]\n```\n\n## Maintainer\n\n- [Nando Vieira](https://github.com/fnando)\n\n## Contributors\n\n- https://github.com/fnando/glob/contributors\n\n## Contributing\n\nFor more details about how to contribute, please read\nhttps://github.com/fnando/glob/blob/main/CONTRIBUTING.md.\n\n## License\n\nThe gem is available as open source under the terms of the\n[MIT License](https://opensource.org/licenses/MIT). A copy of the license can be\nfound at https://github.com/fnando/glob/blob/main/LICENSE.md.\n\n## Code of Conduct\n\nEveryone interacting in the glob project's codebases, issue trackers, chat rooms\nand mailing lists is expected to follow the\n[code of conduct](https://github.com/fnando/glob/blob/main/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fglob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Fglob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fglob/lists"}