{"id":15406854,"url":"https://github.com/dannyben/pobject","last_synced_at":"2026-05-03T04:38:59.762Z","repository":{"id":56888355,"uuid":"62245637","full_name":"DannyBen/pobject","owner":"DannyBen","description":"Automatically persist objects to disk as YAML files","archived":false,"fork":false,"pushed_at":"2023-04-10T06:53:22.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-01T14:12:09.958Z","etag":null,"topics":["config","gem","persistence","persistent-storage","pstore","ruby","yaml"],"latest_commit_sha":null,"homepage":null,"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/DannyBen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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}},"created_at":"2016-06-29T17:42:44.000Z","updated_at":"2023-05-12T17:53:32.000Z","dependencies_parsed_at":"2024-10-01T16:26:00.193Z","dependency_job_id":"040a0133-7309-4af8-9ccc-c21b3dde272e","html_url":"https://github.com/DannyBen/pobject","commit_stats":{"total_commits":22,"total_committers":2,"mean_commits":11.0,"dds":"0.31818181818181823","last_synced_commit":"68d69ea2eff04d9a9eeff8a5b82440ad2d9927fe"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fpobject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fpobject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fpobject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fpobject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DannyBen","download_url":"https://codeload.github.com/DannyBen/pobject/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245956171,"owners_count":20700049,"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":["config","gem","persistence","persistent-storage","pstore","ruby","yaml"],"created_at":"2024-10-01T16:25:58.247Z","updated_at":"2026-05-03T04:38:59.758Z","avatar_url":"https://github.com/DannyBen.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Persistent Object\n==================================================\n\n![repocard](https://repocard.dannyben.com/svg/pobject.svg)\n\nTransparently persist objects to disk as YAML or PStore files.\n\nInstall\n--------------------------------------------------\n\n```\n$ gem install pobject\n```\n\nOr with bundler:\n\n```ruby\ngem 'pobject'\n```\n\nUsage\n--------------------------------------------------\n\nYour object should inherit from `PObject`.\n\n```ruby\nrequire 'pobject'\n\nclass Settings \u003c PObject\nend\n```\n\nNow, any time you access a property, it is saved to a file. By default, we\nwill save a YAML file with the same name as the class.\n\n\n```ruby\nclass Settings \u003c PObject\nend\n\nconfig = Settings.new\nconfig.port = 3000\n# Will create a 'settings.yml' file and store the port value\n```\n\nYou can access any property by either dot notation or hash notation.\n\n```ruby\nconfig.port\n# =\u003e 3000\n\nconfig[:port]\n# =\u003e 3000\n```\n\nTo change the location of the file, simply override the `to_store` method.\n\n```ruby\nclass Settings \u003c PObject\n  def to_store\n    \"config/local.yml\"\n  end\nend\n\nconfig = Settings.new\nconfig.port = 3000\n# Will create a 'config/local.yml'\n```\n\nWhenever you use the `.yml` (or `.yaml`) extension, we will store a YAML \nfile. If you wish to store a `PStore` object instead, use any other \nextension.\n\n```ruby\nclass Settings \u003c PObject\n  def to_store\n    \"config/local.pstore\"\n  end\nend\n```\n\nTo store several objects in one store file, your `to_store` method should \nreturn an array with two elements: The first, is the path to the file and \nthe second is any unique key identifying the instance.\n\n```ruby\nclass Hero \u003c PObject\n  def initialize(id)\n    @id = id\n  end\n\n  def to_store\n    [\"heroes.yml\", @id]\n  end\nend\n\nhammer = Hero.new :hammer\nraynor = Hero.new :raynor\n\nhammer.name = 'Sgt. Hammer'\nraynor.name = 'Raynor'\n\nputs File.read 'heroes.yml'\n# =\u003e \n# ---\n# :hammer:\n#   :name: Sgt. Hammer\n# :raynor:\n#   :name: Raynor\n```\n\nBy default, PObject will raise an error when accessing a property that does\nnot exist. To change this behavior, call `allow_missing` at the beginning of\nyour class.\n\n```ruby\nclass Book \u003c PObject\n  allow_missing\nend\n\nbook = Book.new\nbook.author\n# =\u003e nil\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannyben%2Fpobject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdannyben%2Fpobject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannyben%2Fpobject/lists"}