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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bf7c2de5bc646c5a5a8c54e72d256bd33163ecf
4
- data.tar.gz: 4a614a0c554b9c74e237d48ac0512feb79f96feb
3
+ metadata.gz: dbcfc87af10f53d1290169f4daca8d60c4e7e530
4
+ data.tar.gz: 80cab411cb7b1fb8c7b84172b82ca8d3b23b5be0
5
5
  SHA512:
6
- metadata.gz: c06704a5bcbff3983ec8782153816a3d948ab34036186f49f90cc46d6d242a7828e0b6af9e5aa18f4516c4d35d19e0769690d15d9c730397a12464469bcfa478
7
- data.tar.gz: fa842ef95726e65aa8fdd405b92095dcbb8469dd936cb2e9dc5622f2ed9550c367d2fc3758d6cd1094a3791fee477dac4e9edfc0f770a81d29daa9b9b5e3fff7
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.
@@ -4,12 +4,12 @@ module PersistedHash
4
4
 
5
5
  using Gemmy.patch("hash/i/persisted")
6
6
 
7
- def self.persisted_hash(hash, *args)
7
+ def self.new(hash, *args)
8
8
  hash.persisted *args
9
9
  end
10
10
 
11
11
  def persisted(*args)
12
- PersistedHash.persisted_hash self, *args
12
+ PersistedHash.new self, *args
13
13
  end
14
14
 
15
15
  refine Hash do
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PersistedHash
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
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.1
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