0.0
No commit activity in last 3 years
No release in over 3 years
patch to Hash class to persist to YAML file
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

This was originally written in gemmy but was extracted to a gem.

It's on rubygems. To install gem install persisted_hash and require 'persisted_hash' as expected.

There are three potential ways to create a 'persisted hash':

  1. via a global patch on hash
  2. via a scoped refinement on hash
  3. functionally, via class method

Globally:

Hash.include PersistedHash
hash = {}.persisted("path.yaml")

Refinements:

class MyClass
  using PersistedHash
  hash = {}.persisted("path.yaml")
end

Functionally:

hash = PersistedHash.new({})

The API to interact with the persisted hash is as follows:

  • get(*keys) reads
  • set(*keys) writes
  • data get all
  • set_state(hash) overwrite
  • clear empty

The persisted object inherits from hash, so methods like [] can still be called. They'll just work on the in-memory version, though.