persist 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +21 -17
- data/lib/persist/version.rb +2 -2
- data/lib/persist.rb +17 -19
- metadata +1 -2
- data/.persistent_store +0 -3
data/README.md
CHANGED
@@ -18,33 +18,37 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
Example in IRB:
|
21
|
+
Example in Pry (or IRB):
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
require 'persist'
|
25
|
+
#=> true
|
25
26
|
|
26
|
-
|
27
|
-
#=>
|
28
|
-
|
29
|
-
|
30
|
-
#=>
|
27
|
+
Persist.pull
|
28
|
+
#=> {}
|
29
|
+
|
30
|
+
Persist.store[:siblings] = ["Katie", "Molly", "Shannnon"]
|
31
|
+
#=> ["Katie", "Molly", "Shannnon"]
|
31
32
|
|
32
|
-
|
33
|
+
Persist.push # This saves your Stash to the persistent store.
|
33
34
|
#=> <File:.persistent_store (closed)>
|
35
|
+
```
|
36
|
+
|
37
|
+
You can now quit IRB and your store will persist!
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'persist'
|
41
|
+
#=> true
|
42
|
+
|
43
|
+
Persist.pull
|
44
|
+
#=> {:siblings=>["Katie", "Molly", "Shannnon"]}
|
34
45
|
|
35
|
-
|
36
|
-
|
37
|
-
db = Persist.new # In a new Irb session.
|
38
|
-
#=> #<Persist:0x007fb8c519e7d8 @stash={:siblings=>["Katie", "Molly", "Shannnon"]}
|
39
|
-
|
40
|
-
db.stash[:siblings]
|
46
|
+
Persist.pull[:siblings]
|
41
47
|
#=> ["Katie", "Molly", "Shannnon"]
|
42
48
|
```
|
43
49
|
|
44
50
|
## Contributing
|
45
51
|
|
46
52
|
1. Fork it
|
47
|
-
2.
|
48
|
-
3.
|
49
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
-
5. Create new Pull Request
|
53
|
+
2. Commit your changes (`git commit -am 'Added some feature'`)
|
54
|
+
3. Create new Pull Request
|
data/lib/persist/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
module Persist
|
2
|
+
VERSION = "0.0.2"
|
3
3
|
end
|
data/lib/persist.rb
CHANGED
@@ -1,30 +1,28 @@
|
|
1
1
|
require "persist/version"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Persist
|
4
|
+
class << self
|
5
|
+
STORE = '.persistent_store'
|
5
6
|
|
6
|
-
|
7
|
+
attr_accessor :store
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def pull
|
10
|
+
unless File.exists? STORE
|
11
|
+
self.reset!
|
12
|
+
end
|
13
|
+
@store = Marshal.load File.read(STORE)
|
11
14
|
end
|
12
|
-
self.pull
|
13
|
-
end
|
14
|
-
|
15
|
-
def pull
|
16
|
-
@stash = Marshal.load File.read(STORE)
|
17
|
-
end
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
def push
|
17
|
+
File.open STORE, 'w' do |store|
|
18
|
+
store << Marshal.dump(@store)
|
19
|
+
end
|
22
20
|
end
|
23
|
-
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
def reset!
|
23
|
+
File.open STORE, 'w' do |store|
|
24
|
+
store << Marshal.dump({})
|
25
|
+
end
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: persist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,7 +19,6 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- .gitignore
|
22
|
-
- .persistent_store
|
23
22
|
- Gemfile
|
24
23
|
- LICENSE
|
25
24
|
- README.md
|
data/.persistent_store
DELETED