persist 0.0.6 → 0.0.7

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.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Persist.db
2
2
 
3
- Persist.db is a simple gem that allows you to painlessly save Ruby Objects in a NoSQL persistent file store.
3
+ Persist.db implements a DSL around Ruby Standard Library's PStore to facilitate simple file-persistant storage of Ruby objects in a transactional NoSQL database.
4
4
 
5
5
  ## Installation
6
6
 
@@ -15,8 +15,6 @@ And then execute:
15
15
  Or install it yourself:
16
16
 
17
17
  $ gem install persist
18
-
19
- *Requires Ruby 1.9 or newer.
20
18
 
21
19
  ## Usage
22
20
 
@@ -38,9 +36,12 @@ Persist.pull
38
36
 
39
37
  Persist[:pie] = ['Key Lime', 'Strawberry Rhubarb', 'Blackberry Cobbler']
40
38
  # => ["Key Lime", "Strawberry Rhubarb", "Blackberry Cobbler"]
39
+
40
+ Persist[:ice_cream] = ['chocolate', 'vanilla']
41
+ # => ["chocolate", "vanilla"]
41
42
  ```
42
43
 
43
- You can now quit IRB and your store will persist!
44
+ You can now exit Pry/IRB and your store will persist!
44
45
 
45
46
  ```ruby
46
47
  require 'persist'
@@ -59,12 +60,12 @@ Each of Persist.db's tables is stored as a key:
59
60
 
60
61
  ```ruby
61
62
  Persist.keys
62
- #=> [:pie]
63
+ #=> [:pie, :ice_cream]
63
64
 
64
65
  Persist.key? :pie
65
66
  #=> true
66
67
 
67
- Persist.key? :nope
68
+ Persist.key? :cake
68
69
  #=> false
69
70
  ```
70
71
 
@@ -82,22 +83,27 @@ Persist.path
82
83
  #=> ".db.pstore"
83
84
  ```
84
85
 
85
- Transactions:
86
+ Transactions succeed or fail together to ensure that data is not left in a transitory state:
86
87
 
87
88
  ```ruby
88
89
  Persist.transaction do
89
- Persist.db[:new_key] = 'value'
90
+ Persist.db[:cake] = 'pie is better!'
90
91
  Persist.db.delete :pie
91
- end # If all transactions are succesful, they are commited, otherwise aborted.
92
+ end
92
93
  ```
93
94
 
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
95
+ [Additional documentation](https://github.com/Havenwood/persist/blob/master/lib/persist/persist.rb) in the code.
96
+
97
+ ## Supported Platforms
98
+
99
+ Persist.db makes use of PStore's ultra_safe attribute, which requires:
95
100
 
96
- ## Is It Production Ready™?
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.
101
+ 1. Ruby 1.9 (tested on `ruby-1.9.3` and `rbx --1.9` thus far)
102
+ 2. A POSIX platform (such as OS X, GNU/Linux or FreeBSD)
98
103
 
99
104
  ## Contributing
100
105
 
101
106
  1. Fork it
102
- 2. Commit your changes (`git commit -am 'Did something'`)
103
- 3. Create new Pull Request
107
+ 2. Commit changes (`git commit -am 'did something'`)
108
+ 3. Submit a Pull Request
109
+ 4. :cake:
@@ -1,3 +1,5 @@
1
+ require 'pstore'
2
+
1
3
  # Public: Implements a DSL around Ruby Standard Library's PStore to facilitate
2
4
  # simple file-persistant storage of Ruby objects in a transactional NoSQL
3
5
  # database.
@@ -84,6 +86,31 @@ module Persist
84
86
  end
85
87
  end
86
88
 
89
+ # Public: Fetch a particular table from the persistent store.
90
+ #
91
+ # table - A Symbol corresponding to a root table key in the persistent
92
+ # store.
93
+ #
94
+ # default - An optional value that is returned if the table is not found.
95
+ #
96
+ # Examples
97
+ #
98
+ # Persist.fetch :author
99
+ # # => {:first_name => "Shannon", :last_name => "Skipper"}
100
+ #
101
+ # Persist.fetch :snowman
102
+ # # => nil
103
+ #
104
+ # Persist.fetch :snowman, 'default value instead of nil'
105
+ # # => "default value instead of nil"
106
+ #
107
+ # Returns the value stored in the fetched table.
108
+ def fetch table, default = nil
109
+ @db.transaction true do
110
+ @db.fetch table, default
111
+ end
112
+ end
113
+
87
114
  # Public: Use a single transaction to set a table value.
88
115
  #
89
116
  # table - A Symbol.
@@ -1,3 +1,3 @@
1
1
  module Persist
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/lib/persist.rb CHANGED
@@ -1,3 +1,2 @@
1
- require 'pstore'
2
1
  require 'persist/persist'
3
2
  require 'persist/version'
data/test/test_persist.rb CHANGED
@@ -18,17 +18,17 @@ describe Persist do
18
18
  end
19
19
  end
20
20
 
21
- describe "getting true or false if key exists with Persist.key?(:key)" do
21
+ describe "getting true or false if key exists with Persist.key?" do
22
22
  it "returns true if key exists" do
23
23
  assert Persist.key?(:author)
24
24
  end
25
25
 
26
- it "returns false if the key does't exist" do
26
+ it "returns false if the key doesn't exist" do
27
27
  refute Persist.key?(:this_does_not_exist)
28
28
  end
29
29
  end
30
30
 
31
- describe "getting a particular key's value with Persist[:key]" do
31
+ describe "getting a particular key's value with Persist.[]" do
32
32
  it "returns a value if the key exists" do
33
33
  assert_equal "Shannon", Persist[:author][:first_name]
34
34
  end
@@ -38,7 +38,22 @@ describe Persist do
38
38
  end
39
39
  end
40
40
 
41
- describe "setting a perticular key's value with Persist[:key] = value" do
41
+ describe "getting a particular key or default value with Persist.fetch" do
42
+ it "returns a value if the key exists" do
43
+ assert_equal "Shannon", Persist.fetch(:author)[:first_name]
44
+ end
45
+
46
+ it "returns nil if the key doesn't exist and no default is given" do
47
+ assert_nil Persist.fetch(:this_does_not_exist)
48
+ end
49
+
50
+ it "returns the default value if the key doesn't exist" do
51
+ default = Persist.fetch(:this_does_not_exist, "default value")
52
+ assert_equal "default value", default
53
+ end
54
+ end
55
+
56
+ describe "setting a particular key's value with Persist.[]=" do
42
57
  before do
43
58
  Persist[:trees] = ['oak', 'pine', 'cedar']
44
59
  end
@@ -52,13 +67,13 @@ describe Persist do
52
67
  end
53
68
  end
54
69
 
55
- describe "setting multiple key's values with Persist.transaction do ..." do
70
+ describe "setting multiple key's values with Persist.transaction do" do
56
71
  it "blends" do
57
- assert true #TODO: test.
72
+ assert false #TODO: test.
58
73
  end
59
74
  end
60
75
 
61
- describe "deleting a root key with Persist.delete(:key)" do
76
+ describe "deleting a root key with Persist.delete" do
62
77
  before do
63
78
  Persist.delete :author
64
79
  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.6
4
+ version: 0.0.7
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-23 00:00:00.000000000 Z
12
+ date: 2012-05-25 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