https://github.com/maxpleaner/persisted_hash
Sync a hash's state with YAML file
https://github.com/maxpleaner/persisted_hash
Last synced: about 1 year ago
JSON representation
Sync a hash's state with YAML file
- Host: GitHub
- URL: https://github.com/maxpleaner/persisted_hash
- Owner: MaxPleaner
- Created: 2016-12-21T17:54:11.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-12-22T10:18:15.000Z (over 9 years ago)
- Last Synced: 2024-10-31T02:25:24.538Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 61.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This was originally written in [gemmy](http://github.com/maxpleaner/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:
```rb
Hash.include PersistedHash
hash = {}.persisted("path.yaml")
```
Refinements:
```rb
class MyClass
using PersistedHash
hash = {}.persisted("path.yaml")
end
```
Functionally:
```rb
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.