{"id":19343527,"url":"https://github.com/hex0cter/yaml-ostruct","last_synced_at":"2025-06-11T16:07:55.142Z","repository":{"id":56898931,"uuid":"59823356","full_name":"hex0cter/yaml-ostruct","owner":"hex0cter","description":"Read yaml files recursively from a given directory and return an OpenStruct.","archived":false,"fork":false,"pushed_at":"2018-10-19T21:44:42.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-20T14:45:53.130Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/yaml-ostruct","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-05-27T09:37:24.000Z","updated_at":"2018-10-19T21:42:53.000Z","dependencies_parsed_at":"2022-08-20T17:40:38.453Z","dependency_job_id":null,"html_url":"https://github.com/hex0cter/yaml-ostruct","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/hex0cter/yaml-ostruct","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hex0cter%2Fyaml-ostruct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hex0cter%2Fyaml-ostruct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hex0cter%2Fyaml-ostruct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hex0cter%2Fyaml-ostruct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hex0cter","download_url":"https://codeload.github.com/hex0cter/yaml-ostruct/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hex0cter%2Fyaml-ostruct/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259293389,"owners_count":22835604,"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":[],"created_at":"2024-11-10T03:38:35.646Z","updated_at":"2025-06-11T16:07:55.122Z","avatar_url":"https://github.com/hex0cter.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The yaml-ostruct gem for Ruby\n\n[![Gem Version](https://badge.fury.io/rb/yaml-ostruct.svg)](https://badge.fury.io/rb/yaml-ostruct)\n[![Build Status](https://travis-ci.org/hex0cter/yaml-ostruct.svg?branch=master)](https://travis-ci.org/hex0cter/yaml-ostruct)\n[![Coverage Status](https://coveralls.io/repos/github/hex0cter/yaml-ostruct/badge.svg?branch=master)](https://coveralls.io/github/hex0cter/yaml-ostruct?branch=master)\n\nPreviously known as yaml-sugar, yaml-ostruct is a ruby gem inspired by hashugar. It\nreads all the yaml files from a given directory, and build them into an OpenStruct.\n\nThe gem works in two modes, omitting the directories in which the yaml files are located,\nor having it as part of the structure. By default the later is used. If you want to\nomit the directories, use option omit_path: true in the configure method. In that case,\nfiles with the same name but located in different directories will be merged.\n\n## How to use?\n\nIn your ruby code,\n\n```ruby\n  require 'yaml/ostruct'\n  YamlOstruct.load(dir)\n```\n\nthen you are ready to go.\n\nFor example, if you have the following files inside your config directory:\n\n```\n.\n+-- config\n       +-- fox.yaml\n       +-- asia\n             +-- china\n             |     +-----people.yaml\n             +-- people.yaml\n\n```\n\nconfig/fox.yaml\n```yaml\n  color:\n    is:\n      green: true\n```\n\nconfig/asia/china/people.yaml\n\n```yaml\n    language: chinese\n```\n\nconfig/asia/people.yaml\n\n```yaml\n    language: english\n```\n\nBy default, parent directories of the yaml file are used as part of the structure.\nFor example,\n\n```ruby\n  YamlOstruct.load('config')\n\n  assert YamlOstruct.fox.color.is.brown\n  assert YamlOstruct.asia.china.people.language == 'chinese'\n  assert YamlOstruct.asia.people.language == 'english'\n```\n\nHowever if you want to omit the directories,\n\n```ruby\n  YamlOstruct.configure do |configure|\n    configure.omit_path = true\n  end\n\n  YamlOstruct.load('config')\n\n  assert YamlOstruct.fox.color.is.brown\n  assert YamlOstruct.people.language == 'english'\n```\n\nIn this case if there are multiple files with the same name found in different\ndirectories, they will be merged before the conversion. You can specify\n\n```ruby\n  YamlOstruct.configure do |configure|\n    configure.omit_path = true\n    configure.deep_merge = true\n  end\n\n```\n\nfor a deep merge.\n\nTo skip the errors in parsing the yaml files, you can use\n```ruby\n  YamlOstruct.configure do |configure|\n    configure.skip_error = true\n  end\n```\nYou can also add a dynamic attribute on the fly like this:\n\n```ruby\n  YamlOstruct.attr = :foo\n  assert YamlOstruct.attr == :foo\n```\n\nIf you wanna remove an attribute, you can call\n\n```ruby\n  YamlOstruct.delete(:attr)\n```\n\nIf you wanna clear all the previous settings, just call\n\n```ruby\n  YamlOstruct.clear\n```\n\nOr\n```ruby\n  YamlOstruct.delete_all\n```\n\nSometimes you might want to have multiple instances of YamlOstruct, which are independent\nof each other. In that case you can just use the following syntax:\n\n```ruby\n    config = YamlOstruct.new # Or YamlOstruct.new(omit_path: true, deep_merge: true, skip_error: true)\n    config.load('config')\n\n    config.attr = :land\n    assert config.attr == :land\n```\n\n## How to install?\n\nFrom a terminal run\n\n```bash\n  gem install yaml-ostruct\n```\n\nor add the following code into your Gemfiles:\n\n```ruby\n  gem 'yaml-ostruct'\n```\n\n## How to build/install from source?\n\n```bash\n  gem build yaml-ostruct.gemspec\n  gem install yaml-ostruct-\u003cVERSION\u003e.gem\n```\n\n## How to run the test?\n\n```bash\n  rake test\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/yaml-ostruct/issues), or create a Pull Request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhex0cter%2Fyaml-ostruct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhex0cter%2Fyaml-ostruct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhex0cter%2Fyaml-ostruct/lists"}