persist 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +44 -3
- data/lib/persist/persist.rb +23 -23
- data/lib/persist/version.rb +1 -1
- data/test/test_persist.rb +2 -2
- metadata +2 -2
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Example in Pry (or IRB if you must):
|
|
26
26
|
require 'persist'
|
27
27
|
#=> true
|
28
28
|
|
29
|
-
Persist.
|
29
|
+
Persist.pull
|
30
30
|
# => #<PStore:0x007f8c199c9698
|
31
31
|
@abort=false,
|
32
32
|
@filename=".db.pstore",
|
@@ -45,12 +45,53 @@ You can now quit IRB and your store will persist!
|
|
45
45
|
```ruby
|
46
46
|
require 'persist'
|
47
47
|
#=> true
|
48
|
-
|
48
|
+
|
49
|
+
Persist.pull
|
50
|
+
#=> #<PStore:0x007f8c199c9698 ... >
|
51
|
+
|
49
52
|
Persist[:pie]
|
50
53
|
#=> ["Key Lime", "Strawberry Rhubarb", "Blackberry Cobbler"]
|
51
54
|
```
|
52
55
|
|
53
|
-
|
56
|
+
## Helper Methods
|
57
|
+
|
58
|
+
Each of Persist.db's tables is stored as a key:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
Persist.keys
|
62
|
+
#=> [:pie]
|
63
|
+
|
64
|
+
Persist.key? :pie
|
65
|
+
#=> true
|
66
|
+
|
67
|
+
Persist.key? :nope
|
68
|
+
#=> false
|
69
|
+
```
|
70
|
+
|
71
|
+
Tables can be clobbered:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
Persist.delete :pie
|
75
|
+
#=> nil
|
76
|
+
```
|
77
|
+
|
78
|
+
To check the location of your persistent store file:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
Persist.path
|
82
|
+
#=> ".db.pstore"
|
83
|
+
```
|
84
|
+
|
85
|
+
Transactions:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
Persist.transaction do
|
89
|
+
Persist.db[:new_key] = 'value'
|
90
|
+
Persist.db.delete :pie
|
91
|
+
end # If all transactions are succesful, they are commited, otherwise aborted.
|
92
|
+
```
|
93
|
+
|
94
|
+
TODO: Better README. In the meanwhile, documentation is better in the code itself: https://github.com/Havenwood/persist/blob/master/lib/persist/persist.rb
|
54
95
|
|
55
96
|
## Is It Production Ready™?
|
56
97
|
No. Persist.db is early Alpha, but please try it out and let me know if you find any bugs or real-world performance problems.
|
data/lib/persist/persist.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
module Persist
|
5
5
|
class << self
|
6
6
|
# Public: Returns the persistant store Object if initialized.
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :db
|
8
8
|
|
9
9
|
# Public: Initialize the PStore Object--deserializing the marshalled Hash
|
10
10
|
# stored in the '.db.pstore' file (creating the file if it does't exist)--
|
@@ -12,7 +12,7 @@ module Persist
|
|
12
12
|
#
|
13
13
|
# Examples
|
14
14
|
#
|
15
|
-
# Persist.
|
15
|
+
# Persist.pull
|
16
16
|
# # => #<PStore:0x007f8c199c9698
|
17
17
|
# @abort=false,
|
18
18
|
# @filename=".db.pstore",
|
@@ -23,11 +23,11 @@ module Persist
|
|
23
23
|
# @ultra_safe=true>
|
24
24
|
#
|
25
25
|
# Returns the entire persistent store Object.
|
26
|
-
def
|
27
|
-
@
|
28
|
-
@
|
29
|
-
@
|
30
|
-
@
|
26
|
+
def pull
|
27
|
+
@db = PStore.new '.db.pstore', true
|
28
|
+
@db.ultra_safe = true
|
29
|
+
@db.transaction(true) {}
|
30
|
+
@db
|
31
31
|
end
|
32
32
|
|
33
33
|
# Public: Fetch a list of persistent store root tables.
|
@@ -39,8 +39,8 @@ module Persist
|
|
39
39
|
#
|
40
40
|
# Returns an Array containing the persistent store root tables.
|
41
41
|
def keys
|
42
|
-
@
|
43
|
-
@
|
42
|
+
@db.transaction true do
|
43
|
+
@db.roots
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -59,8 +59,8 @@ module Persist
|
|
59
59
|
#
|
60
60
|
# Returns true or false.
|
61
61
|
def key? table
|
62
|
-
@
|
63
|
-
@
|
62
|
+
@db.transaction true do
|
63
|
+
@db.root? table
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -79,8 +79,8 @@ module Persist
|
|
79
79
|
#
|
80
80
|
# Returns the value stored in the fetched table.
|
81
81
|
def [] table
|
82
|
-
@
|
83
|
-
@
|
82
|
+
@db.transaction true do
|
83
|
+
@db[table]
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -97,8 +97,8 @@ module Persist
|
|
97
97
|
#
|
98
98
|
# Returns the value of the table.
|
99
99
|
def []= table, value
|
100
|
-
@
|
101
|
-
@
|
100
|
+
@db.transaction do
|
101
|
+
@db[table] = value
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -112,16 +112,16 @@ module Persist
|
|
112
112
|
# Examples
|
113
113
|
#
|
114
114
|
# Persist.transaction do
|
115
|
-
# Persist.
|
116
|
-
# Persist.
|
115
|
+
# Persist.db[:weather] = 'sunny'
|
116
|
+
# Persist.db.delete[:author]
|
117
117
|
# end
|
118
118
|
# # => nil
|
119
119
|
#
|
120
120
|
# Returns nothing.
|
121
121
|
def transaction &block
|
122
|
-
@
|
122
|
+
@db.transaction do
|
123
123
|
yield
|
124
|
-
@
|
124
|
+
@db.commit
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -140,11 +140,11 @@ module Persist
|
|
140
140
|
#
|
141
141
|
# Returns nothing.
|
142
142
|
def delete *tables
|
143
|
-
@
|
143
|
+
@db.transaction do
|
144
144
|
tables.each do |table|
|
145
|
-
@
|
145
|
+
@db.delete table
|
146
146
|
end
|
147
|
-
@
|
147
|
+
@db.commit
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
@@ -157,7 +157,7 @@ module Persist
|
|
157
157
|
#
|
158
158
|
# Returns the path to the data file as a String.
|
159
159
|
def path
|
160
|
-
@
|
160
|
+
@db.path
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
data/lib/persist/version.rb
CHANGED
data/test/test_persist.rb
CHANGED
@@ -2,13 +2,13 @@ require_relative 'helper'
|
|
2
2
|
|
3
3
|
describe Persist do
|
4
4
|
before do
|
5
|
-
|
5
|
+
Persist.pull
|
6
6
|
Persist[:author] = {first_name: 'Shannon', last_name: 'Skipper'}
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "initializing the persistent store with Persist.db" do
|
10
10
|
it "returns a PStore object" do
|
11
|
-
assert_equal PStore,
|
11
|
+
assert_equal PStore, Persist.db.class
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
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.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A DSL for storing Ruby Objects transactionally in a persistent NoSQL
|
15
15
|
database
|