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 CHANGED
@@ -26,7 +26,7 @@ Example in Pry (or IRB if you must):
26
26
  require 'persist'
27
27
  #=> true
28
28
 
29
- Persist.db
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
- TODO: Document Persist.db's other public methods such as #transaction, #delete, #path, #key? and #keys. The best documentation in the meanwhile is in the code itself: https://github.com/Havenwood/persist/blob/master/lib/persist/persist.rb
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.
@@ -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 :store
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.db
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 db
27
- @store = PStore.new '.db.pstore', true
28
- @store.ultra_safe = true
29
- @store.transaction(true) {}
30
- @store
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
- @store.transaction true do
43
- @store.roots
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
- @store.transaction true do
63
- @store.root? table
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
- @store.transaction true do
83
- @store[table]
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
- @store.transaction do
101
- @store[table] = value
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.store[:weather] = 'sunny'
116
- # Persist.store[:hour] = 'midday'
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
- @store.transaction do
122
+ @db.transaction do
123
123
  yield
124
- @store.commit
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
- @store.transaction do
143
+ @db.transaction do
144
144
  tables.each do |table|
145
- @store.delete table
145
+ @db.delete table
146
146
  end
147
- @store.commit
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
- @store.path
160
+ @db.path
161
161
  end
162
162
  end
163
163
  end
@@ -1,3 +1,3 @@
1
1
  module Persist
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
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
- @db = Persist.db
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, @db.class
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.5
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-22 00:00:00.000000000 Z
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