persisted_hash 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +41 -0
- data/lib/persisted_hash.rb +2 -2
- data/lib/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbcfc87af10f53d1290169f4daca8d60c4e7e530
|
4
|
+
data.tar.gz: 80cab411cb7b1fb8c7b84172b82ca8d3b23b5be0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19734863251e5a350133dd8ef6c0a72838d26fe3ee305209e0b688e09ffa2b53043f789ed8f6dad03e8417d11583c79f2d05c7bf15c4d1bacdf9920f484ac141
|
7
|
+
data.tar.gz: 615c058a6b6106c2209ddfb4bf6a6eab0cbdc71764b977af505902231e3cbb20f21217fee04f5e561dd3251ee8852f3ff0fb3536872c3db145c0f939d90e340a
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
This was originally written in [gemmy](http://github.com/maxpleaner/gemmy) but was extracted to a gem.
|
2
|
+
|
3
|
+
It's on rubygems. To install `gem install persisted_hash` and `require 'persisted_hash'` as expected.
|
4
|
+
|
5
|
+
There are three potential ways to create a 'persisted hash':
|
6
|
+
|
7
|
+
1. via a global patch on hash
|
8
|
+
2. via a scoped refinement on hash
|
9
|
+
3. functionally, via class method
|
10
|
+
|
11
|
+
Globally:
|
12
|
+
|
13
|
+
```rb
|
14
|
+
Hash.include PersistedHash
|
15
|
+
hash = {}.persisted("path.yaml")
|
16
|
+
```
|
17
|
+
|
18
|
+
Refinements:
|
19
|
+
|
20
|
+
```rb
|
21
|
+
class MyClass
|
22
|
+
using PersistedHash
|
23
|
+
hash = {}.persisted("path.yaml")
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
Functionally:
|
28
|
+
|
29
|
+
```rb
|
30
|
+
hash = PersistedHash.new({})
|
31
|
+
```
|
32
|
+
The API to interact with the persisted hash is as follows:
|
33
|
+
|
34
|
+
- `get(*keys)` reads
|
35
|
+
- `set(*keys)` writes
|
36
|
+
- `data` get all
|
37
|
+
- `set_state(hash)` overwrite
|
38
|
+
- `clear` empty
|
39
|
+
|
40
|
+
The persisted object inherits from hash, so methods like `[]` can still be called.
|
41
|
+
They'll just work on the in-memory version, though.
|
data/lib/persisted_hash.rb
CHANGED
@@ -4,12 +4,12 @@ module PersistedHash
|
|
4
4
|
|
5
5
|
using Gemmy.patch("hash/i/persisted")
|
6
6
|
|
7
|
-
def self.
|
7
|
+
def self.new(hash, *args)
|
8
8
|
hash.persisted *args
|
9
9
|
end
|
10
10
|
|
11
11
|
def persisted(*args)
|
12
|
-
PersistedHash.
|
12
|
+
PersistedHash.new self, *args
|
13
13
|
end
|
14
14
|
|
15
15
|
refine Hash do
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: persisted_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maxpleaner
|
@@ -31,6 +31,7 @@ executables:
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- README.md
|
34
35
|
- bin/persisted_hash
|
35
36
|
- lib/persisted_hash.rb
|
36
37
|
- lib/version.rb
|