bin 0.6.2 → 0.6.3
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/lib/bin/store.rb +5 -3
- data/lib/bin/version.rb +1 -1
- data/spec/bin/store_spec.rb +36 -6
- metadata +3 -3
data/lib/bin/store.rb
CHANGED
@@ -12,6 +12,7 @@ module Bin
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def write(key, value, options={})
|
15
|
+
key = key.to_s
|
15
16
|
super do
|
16
17
|
expires = Time.now.utc + ((options && options[:expires_in]) || expires_in)
|
17
18
|
raw = !!options[:raw]
|
@@ -23,7 +24,7 @@ module Bin
|
|
23
24
|
|
24
25
|
def read(key, options=nil)
|
25
26
|
super do
|
26
|
-
if doc = collection.find_one(:_id => key, :expires_at => {'$gt' => Time.now.utc})
|
27
|
+
if doc = collection.find_one(:_id => key.to_s, :expires_at => {'$gt' => Time.now.utc})
|
27
28
|
doc['raw'] ? doc['value'] : Marshal.load(doc['value'].to_s)
|
28
29
|
end
|
29
30
|
end
|
@@ -31,7 +32,7 @@ module Bin
|
|
31
32
|
|
32
33
|
def delete(key, options=nil)
|
33
34
|
super do
|
34
|
-
collection.remove(:_id => key)
|
35
|
+
collection.remove(:_id => key.to_s)
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
@@ -69,11 +70,12 @@ module Bin
|
|
69
70
|
|
70
71
|
private
|
71
72
|
def counter_key_upsert(key, amount)
|
73
|
+
key = key.to_s
|
72
74
|
collection.update(
|
73
75
|
{:_id => key}, {
|
74
76
|
'$inc' => {:value => amount},
|
75
77
|
'$set' => {
|
76
|
-
:expires_at => Time.now.utc + 1.year,
|
78
|
+
:expires_at => Time.now.utc + 1.year,
|
77
79
|
:raw => true
|
78
80
|
},
|
79
81
|
}, :upsert => true)
|
data/lib/bin/version.rb
CHANGED
data/spec/bin/store_spec.rb
CHANGED
@@ -6,13 +6,10 @@ describe Bin::Store do
|
|
6
6
|
collection.remove
|
7
7
|
collection.drop_indexes
|
8
8
|
end
|
9
|
-
|
10
|
-
@collection = DB['bin_cache']
|
11
|
-
@store = Bin::Store.new(@collection)
|
12
9
|
end
|
13
10
|
|
14
|
-
let(:
|
15
|
-
let(:
|
11
|
+
let(:collection) { DB['bin_cache'] }
|
12
|
+
let(:store) { Bin::Store.new(collection) }
|
16
13
|
|
17
14
|
it "has a collection" do
|
18
15
|
store.collection.should == collection
|
@@ -23,7 +20,7 @@ describe Bin::Store do
|
|
23
20
|
end
|
24
21
|
|
25
22
|
it "can set default expires_in" do
|
26
|
-
Bin::Store.new(
|
23
|
+
Bin::Store.new(collection, :expires_in => 5.minutes).expires_in.should == 5.minutes
|
27
24
|
end
|
28
25
|
|
29
26
|
describe "#write" do
|
@@ -59,6 +56,13 @@ describe Bin::Store do
|
|
59
56
|
store.write('foo', 'bar', :expires_in => 5.seconds)
|
60
57
|
document['expires_at'].to_i.should == (Time.now.utc + 5.seconds).to_i
|
61
58
|
end
|
59
|
+
|
60
|
+
it "always sets key as string" do
|
61
|
+
store.write(:baz, 'wick')
|
62
|
+
doc = collection.find_one(:_id => 'baz')
|
63
|
+
doc.should_not be_nil
|
64
|
+
doc['_id'].should be_instance_of(String)
|
65
|
+
end
|
62
66
|
end
|
63
67
|
|
64
68
|
describe "#read" do
|
@@ -89,6 +93,10 @@ describe Bin::Store do
|
|
89
93
|
store.write('foo', 'bar', :expires_in => 20.seconds)
|
90
94
|
store.read('foo').should == 'bar'
|
91
95
|
end
|
96
|
+
|
97
|
+
it "works with symbol" do
|
98
|
+
store.read(:foo).should == 'bar'
|
99
|
+
end
|
92
100
|
end
|
93
101
|
|
94
102
|
describe "#delete" do
|
@@ -101,6 +109,12 @@ describe Bin::Store do
|
|
101
109
|
store.delete('foo')
|
102
110
|
store.read('foo').should be_nil
|
103
111
|
end
|
112
|
+
|
113
|
+
it "works with symbol" do
|
114
|
+
store.read(:foo).should_not be_nil
|
115
|
+
store.delete(:foo)
|
116
|
+
store.read(:foo).should be_nil
|
117
|
+
end
|
104
118
|
end
|
105
119
|
|
106
120
|
describe "#delete_matched" do
|
@@ -136,6 +150,11 @@ describe Bin::Store do
|
|
136
150
|
it "returns false if key not found" do
|
137
151
|
store.exist?('not:found:key').should be_false
|
138
152
|
end
|
153
|
+
|
154
|
+
it "works with symbol" do
|
155
|
+
store.exist?(:foo).should be_true
|
156
|
+
store.exist?(:notfoundkey).should be_false
|
157
|
+
end
|
139
158
|
end
|
140
159
|
|
141
160
|
describe "#clear" do
|
@@ -158,6 +177,11 @@ describe Bin::Store do
|
|
158
177
|
store.increment('views', 2)
|
159
178
|
store.read('views').should == 3
|
160
179
|
end
|
180
|
+
|
181
|
+
it "works with symbol" do
|
182
|
+
store.increment(:views, 2)
|
183
|
+
store.read(:views).should == 2
|
184
|
+
end
|
161
185
|
end
|
162
186
|
|
163
187
|
describe "#decrement" do
|
@@ -168,6 +192,12 @@ describe Bin::Store do
|
|
168
192
|
store.decrement('views', 2)
|
169
193
|
store.read('views').should == 1
|
170
194
|
end
|
195
|
+
|
196
|
+
it "works with symbol" do
|
197
|
+
store.increment(:views, 2)
|
198
|
+
store.decrement(:views, 1)
|
199
|
+
store.read(:views).should == 1
|
200
|
+
end
|
171
201
|
end
|
172
202
|
|
173
203
|
describe "#stats" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 0.6.
|
8
|
+
- 3
|
9
|
+
version: 0.6.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Nunemaker
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-15 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|