moneta 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +26 -8
  3. data/CHANGES +6 -0
  4. data/CONTRIBUTORS +2 -1
  5. data/Gemfile +7 -5
  6. data/README.md +2 -6
  7. data/feature_matrix.yaml +0 -10
  8. data/lib/moneta.rb +9 -9
  9. data/lib/moneta/adapters/mongo.rb +256 -7
  10. data/lib/moneta/adapters/redis.rb +5 -1
  11. data/lib/moneta/adapters/sequel.rb +45 -464
  12. data/lib/moneta/adapters/sequel/mysql.rb +66 -0
  13. data/lib/moneta/adapters/sequel/postgres.rb +80 -0
  14. data/lib/moneta/adapters/sequel/postgres_hstore.rb +240 -0
  15. data/lib/moneta/adapters/sequel/sqlite.rb +57 -0
  16. data/lib/moneta/adapters/sqlite.rb +7 -7
  17. data/lib/moneta/create_support.rb +21 -0
  18. data/lib/moneta/dbm_adapter.rb +31 -0
  19. data/lib/moneta/{mixins.rb → defaults.rb} +1 -302
  20. data/lib/moneta/each_key_support.rb +27 -0
  21. data/lib/moneta/expires_support.rb +60 -0
  22. data/lib/moneta/hash_adapter.rb +68 -0
  23. data/lib/moneta/increment_support.rb +16 -0
  24. data/lib/moneta/nil_values.rb +35 -0
  25. data/lib/moneta/option_support.rb +51 -0
  26. data/lib/moneta/transformer/helper/bson.rb +5 -15
  27. data/lib/moneta/version.rb +1 -1
  28. data/lib/rack/cache/moneta.rb +14 -15
  29. data/moneta.gemspec +7 -9
  30. data/script/benchmarks +1 -2
  31. data/script/contributors +11 -6
  32. data/spec/active_support/cache_moneta_store_spec.rb +27 -29
  33. data/spec/features/concurrent_increment.rb +2 -3
  34. data/spec/features/create_expires.rb +15 -15
  35. data/spec/features/default_expires.rb +11 -12
  36. data/spec/features/expires.rb +215 -210
  37. data/spec/helper.rb +16 -33
  38. data/spec/moneta/adapters/mongo/adapter_mongo_spec.rb +16 -1
  39. data/spec/moneta/adapters/mongo/adapter_mongo_with_default_expires_spec.rb +1 -1
  40. data/spec/moneta/adapters/mongo/standard_mongo_spec.rb +1 -1
  41. data/spec/moneta/adapters/sequel/adapter_sequel_spec.rb +7 -34
  42. data/spec/moneta/adapters/sequel/helper.rb +37 -0
  43. data/spec/moneta/adapters/sequel/standard_sequel_spec.rb +4 -10
  44. data/spec/moneta/adapters/sequel/standard_sequel_with_expires_spec.rb +7 -8
  45. data/spec/moneta/proxies/shared/shared_unix_spec.rb +10 -0
  46. data/spec/restserver.rb +15 -0
  47. metadata +39 -58
  48. data/lib/moneta/adapters/mongo/base.rb +0 -103
  49. data/lib/moneta/adapters/mongo/moped.rb +0 -166
  50. data/lib/moneta/adapters/mongo/official.rb +0 -156
  51. data/spec/moneta/adapters/mongo/adapter_mongo_moped_spec.rb +0 -26
  52. data/spec/moneta/adapters/mongo/adapter_mongo_moped_with_default_expires_spec.rb +0 -14
  53. data/spec/moneta/adapters/mongo/adapter_mongo_official_spec.rb +0 -27
  54. data/spec/moneta/adapters/mongo/adapter_mongo_official_with_default_expires_spec.rb +0 -14
  55. data/spec/moneta/adapters/mongo/standard_mongo_moped_spec.rb +0 -7
  56. data/spec/moneta/adapters/mongo/standard_mongo_official_spec.rb +0 -7
  57. data/spec/quality_spec.rb +0 -51
@@ -3,289 +3,294 @@ shared_examples :expires do
3
3
  raise "t_res must be <= min_ttl" unless t_res <= min_ttl
4
4
  end
5
5
 
6
- at_each_usec do
7
- # All methods that are used for updating that include an :expires parameter
8
- shared_examples :updater_expiry do
9
- context "with a positive numeric :expires parameter" do
10
- before do
11
- updater.call(expires: min_ttl)
12
- end
6
+ # All methods that are used for updating that include an :expires parameter
7
+ shared_examples :updater_expiry do
8
+ context "with a positive numeric :expires parameter" do
9
+ before do
10
+ updater.call(expires: min_ttl)
11
+ end
13
12
 
14
- it 'causes the value to expire after the given number of seconds' do
15
- keys.zip(values).each do |key, value|
16
- expect(store.load(key)).to eq value
17
- expect(store[key]).to eq value
18
- end
19
- advance min_ttl + t_res
20
- keys.each do |key, value|
21
- expect(store.load(key)).to be_nil
22
- expect(store[key]).to be_nil
23
- end
13
+ it 'causes the value to expire after the given number of seconds' do
14
+ keys.zip(values).each do |key, value|
15
+ expect(store.load(key)).to eq value
16
+ expect(store[key]).to eq value
17
+ end
18
+ advance min_ttl
19
+ 2.times { advance_next_tick }
20
+ keys.each do |key, value|
21
+ expect(store.load(key)).to be_nil
22
+ expect(store[key]).to be_nil
24
23
  end
25
24
  end
25
+ end
26
26
 
27
- shared_examples :updater_no_expires do
28
- it 'causes the value not to expire after the given number of seconds' do
29
- updater.call(expires: expires)
30
- keys.zip(values).each do |key, value|
31
- expect(store.load(key)).to eq value
32
- expect(store[key]).to eq value
33
- end
34
- advance min_ttl + t_res
35
- keys.zip(values).each do |key, value|
36
- expect(store.load(key)).to eq value
37
- expect(store[key]).to eq value
38
- end
27
+ shared_examples :updater_no_expires do
28
+ it 'causes the value not to expire after the given number of seconds' do
29
+ updater.call(expires: expires)
30
+ keys.zip(values).each do |key, value|
31
+ expect(store.load(key)).to eq value
32
+ expect(store[key]).to eq value
33
+ end
34
+ advance min_ttl
35
+ 2.times { advance_next_tick }
36
+ keys.zip(values).each do |key, value|
37
+ expect(store.load(key)).to eq value
38
+ expect(store[key]).to eq value
39
39
  end
40
40
  end
41
+ end
41
42
 
42
- context "with a zero :expires parameter" do
43
- let(:expires) { 0 }
44
- include_examples :updater_no_expires
45
- end
43
+ context "with a zero :expires parameter" do
44
+ let(:expires) { 0 }
45
+ include_examples :updater_no_expires
46
+ end
46
47
 
47
- context "with a false :expires parameter" do
48
- let(:expires) { false }
49
- include_examples :updater_no_expires
50
- end
48
+ context "with a false :expires parameter" do
49
+ let(:expires) { false }
50
+ include_examples :updater_no_expires
51
51
  end
52
+ end
52
53
 
53
- # All methods that are used to for loading, and that include an expire parameter
54
- shared_examples :loader_expiry do
55
- it "does not affect expiry if the value is not present" do
56
- expect(loader.call(expires: min_ttl)).to be_absent
57
- expect(loader.call).to be_absent
58
- end
54
+ # All methods that are used to for loading, and that include an expire parameter
55
+ shared_examples :loader_expiry do
56
+ it "does not affect expiry if the value is not present" do
57
+ expect(loader.call(expires: min_ttl)).to be_absent
58
+ expect(loader.call).to be_absent
59
+ end
59
60
 
60
- shared_examples :loader_expires do
61
- context 'when passed a positive numeric :expires parameter' do
62
- it 'changes the expiry of the value(s) to the given number of seconds' do
63
- expect(loader.call).to be_present
64
- expect(loader.call(expires: min_ttl + 2 * t_res)).to be_present
65
- advance min_ttl + t_res
66
- expect(loader.call).to be_present
67
- advance 2 * t_res
68
- expect(loader.call).to be_absent
69
- end
61
+ shared_examples :loader_expires do
62
+ context 'when passed a positive numeric :expires parameter' do
63
+ it 'changes the expiry of the value(s) to the given number of seconds' do
64
+ expect(loader.call).to be_present
65
+ expect(loader.call(expires: min_ttl + 2 * t_res)).to be_present
66
+ advance min_ttl
67
+ advance_next_tick
68
+ expect(loader.call).to be_present
69
+ 2.times { advance_next_tick }
70
+ expect(loader.call).to be_absent
70
71
  end
71
72
  end
73
+ end
72
74
 
73
- context 'with previously stored expiring value(s)' do
74
- before do
75
- keys.zip(values).each do |key, value|
76
- store.store(key, value, expires: min_ttl)
77
- end
75
+ context 'with previously stored expiring value(s)' do
76
+ before do
77
+ keys.zip(values).each do |key, value|
78
+ store.store(key, value, expires: min_ttl)
78
79
  end
79
- include_examples :loader_expires
80
-
81
- shared_examples :loader_no_expires do
82
- it "changes the expiry of the value(s) so that they don't expire" do
83
- expect(loader.call(expires: expires)).to be_present
84
- advance min_ttl + t_res
85
- expect(loader.call).to be_present
86
- end
80
+ end
81
+ include_examples :loader_expires
82
+
83
+ shared_examples :loader_no_expires do
84
+ it "changes the expiry of the value(s) so that they don't expire" do
85
+ expect(loader.call(expires: expires)).to be_present
86
+ advance min_ttl
87
+ advance_next_tick
88
+ expect(loader.call).to be_present
87
89
  end
90
+ end
88
91
 
89
- context "when passed a zero :expires parameter" do
90
- let(:expires) { 0 }
91
- include_examples :loader_no_expires
92
- end
92
+ context "when passed a zero :expires parameter" do
93
+ let(:expires) { 0 }
94
+ include_examples :loader_no_expires
95
+ end
93
96
 
94
- context "when passed false :expires parameter" do
95
- let(:expires) { false }
96
- include_examples :loader_no_expires
97
- end
97
+ context "when passed false :expires parameter" do
98
+ let(:expires) { false }
99
+ include_examples :loader_no_expires
100
+ end
98
101
 
99
- shared_examples :loader_no_effect do
100
- it 'does not affect the expiry time' do
101
- expect(loader_no_effect.call).to be_present
102
- advance min_ttl + t_res
103
- expect(loader.call).to be_absent
104
- end
102
+ shared_examples :loader_no_effect do
103
+ it 'does not affect the expiry time' do
104
+ expect(loader_no_effect.call).to be_present
105
+ advance min_ttl
106
+ advance_next_tick
107
+ expect(loader.call).to be_absent
105
108
  end
109
+ end
106
110
 
107
- context 'when passed a nil :expires parameter' do
108
- let(:loader_no_effect) { lambda { loader.call(expires: nil) } }
109
- include_examples :loader_no_effect
110
- end
111
+ context 'when passed a nil :expires parameter' do
112
+ let(:loader_no_effect) { lambda { loader.call(expires: nil) } }
113
+ include_examples :loader_no_effect
114
+ end
111
115
 
112
- context 'when not passed an :expires parameter' do
113
- let(:loader_no_effect) { loader }
114
- include_examples :loader_no_effect
115
- end
116
+ context 'when not passed an :expires parameter' do
117
+ let(:loader_no_effect) { loader }
118
+ include_examples :loader_no_effect
116
119
  end
120
+ end
117
121
 
118
- context "with previously stored not expiring value(s)" do
119
- before do
120
- keys.zip(values).each do |key, value|
121
- store.store(key, value, expires: false)
122
- end
122
+ context "with previously stored not expiring value(s)" do
123
+ before do
124
+ keys.zip(values).each do |key, value|
125
+ store.store(key, value, expires: false)
123
126
  end
124
- include_examples :loader_expires
125
127
  end
128
+ include_examples :loader_expires
126
129
  end
130
+ end
127
131
 
128
- describe '#store' do
129
- let(:keys) { ['key1'] }
130
- let(:values) { ['value1'] }
131
- let(:updater) do
132
- lambda do |**options|
133
- expect(store.store(keys[0], values[0], options)).to eq values[0]
134
- end
132
+ describe '#store' do
133
+ let(:keys) { ['key1'] }
134
+ let(:values) { ['value1'] }
135
+ let(:updater) do
136
+ lambda do |**options|
137
+ expect(store.store(keys[0], values[0], options)).to eq values[0]
135
138
  end
139
+ end
136
140
 
137
- include_examples :updater_expiry
141
+ include_examples :updater_expiry
142
+ end
143
+
144
+ describe '#load' do
145
+ let(:keys) { ['key1'] }
146
+ let(:values) { ['value1'] }
147
+ let(:loader) do
148
+ lambda { |**options| store.load('key1', options) }
149
+ end
150
+ let(:be_present) { eq 'value1' }
151
+ let(:be_absent) { be_nil }
152
+
153
+ include_examples :loader_expiry
154
+ end
155
+
156
+ describe '#key?' do
157
+ let(:keys) { ['key1'] }
158
+ let(:values) { ['value1'] }
159
+ let(:loader) do
160
+ lambda { |**options| store.key?('key1', options) }
138
161
  end
162
+ let(:be_present) { be true }
163
+ let(:be_absent) { be false }
164
+
165
+ include_examples :loader_expiry
166
+ end
139
167
 
140
- describe '#load' do
141
- let(:keys) { ['key1'] }
142
- let(:values) { ['value1'] }
168
+ describe '#fetch' do
169
+ let(:keys) { ['key1'] }
170
+ let(:values) { ['value1'] }
171
+ let(:be_present) { eq 'value1' }
172
+
173
+ context "with default given as second parameter" do
143
174
  let(:loader) do
144
- lambda { |**options| store.load('key1', options) }
175
+ lambda { |**options| store.fetch('key1', 'missing', options) }
145
176
  end
146
- let(:be_present) { eq 'value1' }
147
- let(:be_absent) { be_nil }
177
+ let(:be_absent) { eq 'missing' }
148
178
 
149
179
  include_examples :loader_expiry
150
180
  end
151
181
 
152
- describe '#key?' do
153
- let(:keys) { ['key1'] }
154
- let(:values) { ['value1'] }
182
+ context "with default given as a block" do
155
183
  let(:loader) do
156
- lambda { |**options| store.key?('key1', options) }
184
+ lambda { |**options| store.fetch('key1', options) { 'missing' } }
157
185
  end
158
- let(:be_present) { be true }
159
- let(:be_absent) { be false }
186
+ let(:be_absent) { eq 'missing' }
160
187
 
161
188
  include_examples :loader_expiry
162
189
  end
163
190
 
164
- describe '#fetch' do
165
- let(:keys) { ['key1'] }
166
- let(:values) { ['value1'] }
167
- let(:be_present) { eq 'value1' }
168
-
169
- context "with default given as second parameter" do
170
- let(:loader) do
171
- lambda { |**options| store.fetch('key1', 'missing', options) }
172
- end
173
- let(:be_absent) { eq 'missing' }
174
-
175
- include_examples :loader_expiry
191
+ context "with nil default given" do
192
+ let(:loader) do
193
+ lambda { |**options| store.fetch('key1', nil, options) }
176
194
  end
195
+ let(:be_absent) { be_nil }
177
196
 
178
- context "with default given as a block" do
179
- let(:loader) do
180
- lambda { |**options| store.fetch('key1', options) { 'missing' } }
181
- end
182
- let(:be_absent) { eq 'missing' }
197
+ include_examples :loader_expiry
198
+ end
199
+ end
183
200
 
184
- include_examples :loader_expiry
201
+ describe '#delete' do
202
+ context 'with an already expired value' do
203
+ before do
204
+ store.store('key2', 'val2', expires: min_ttl)
205
+ expect(store['key2']).to eq 'val2'
206
+ advance min_ttl
207
+ advance_next_tick
185
208
  end
186
209
 
187
- context "with nil default given" do
188
- let(:loader) do
189
- lambda { |**options| store.fetch('key1', nil, options) }
190
- end
191
- let(:be_absent) { be_nil }
192
-
193
- include_examples :loader_expiry
210
+ it 'does not return the expired value' do
211
+ expect(store.delete('key2')).to be_nil
194
212
  end
195
213
  end
214
+ end
196
215
 
197
- describe '#delete' do
198
- context 'with an already expired value' do
199
- before do
200
- store.store('key2', 'val2', expires: min_ttl)
201
- expect(store['key2']).to eq 'val2'
202
- advance min_ttl + t_res
203
- end
216
+ describe '#expires' do
217
+ it "returns a store with access to the same items" do
218
+ store.store('persistent_key', 'persistent_value', expires: false)
219
+ store_expires = store.expires(min_ttl)
220
+ expect(store_expires['persistent_key']).to eq 'persistent_value'
221
+ end
204
222
 
205
- it 'does not return the expired value' do
206
- expect(store.delete('key2')).to be_nil
207
- end
208
- end
223
+ it "returns a store with default expiry set" do
224
+ store_expires = store.expires(min_ttl)
225
+ expect(store_expires.store('key1', 'val1')).to eq 'val1'
226
+ expect(store_expires['key1']).to eq 'val1'
227
+ advance min_ttl
228
+ advance_next_tick
229
+ expect(store['key1']).to be_nil
209
230
  end
231
+ end
210
232
 
211
- describe '#expires' do
212
- it "returns a store with access to the same items" do
213
- store.store('persistent_key', 'persistent_value', expires: false)
214
- store_expires = store.expires(min_ttl)
215
- expect(store_expires['persistent_key']).to eq 'persistent_value'
233
+ describe '#merge!' do
234
+ let(:keys) { ['key1', 'key2'] }
235
+ let(:values) { ['value1', 'value2'] }
236
+ let(:updater) do
237
+ lambda do |**options|
238
+ expect(store.merge!(keys.zip(values), options)).to eq store
216
239
  end
240
+ end
217
241
 
218
- it "returns a store with default expiry set" do
219
- store_expires = store.expires(min_ttl)
220
- expect(store_expires.store('key1', 'val1')).to eq 'val1'
221
- expect(store_expires['key1']).to eq 'val1'
222
- advance min_ttl + t_res
223
- expect(store['key1']).to be_nil
224
- end
242
+ include_examples :updater_expiry
243
+ end
244
+
245
+ describe '#values_at' do
246
+ let(:keys) { ['key1', 'key2'] }
247
+ let(:values) { ['value1', 'value2'] }
248
+ let(:loader) do
249
+ lambda { |**options| store.values_at('key1', 'key2', **options) }
225
250
  end
251
+ let(:be_present) { eq ['value1', 'value2'] }
252
+ let(:be_absent) { eq [nil, nil] }
226
253
 
227
- describe '#merge!' do
228
- let(:keys) { ['key1', 'key2'] }
229
- let(:values) { ['value1', 'value2'] }
230
- let(:updater) do
254
+ include_examples :loader_expiry
255
+ end
256
+
257
+ describe '#fetch_values' do
258
+ let(:keys) { ['key1', 'key2'] }
259
+ let(:values) { ['value1', 'value2'] }
260
+ let(:be_present) { eq ['value1', 'value2'] }
261
+
262
+ context 'with default values given via a block' do
263
+ let(:loader) do
231
264
  lambda do |**options|
232
- expect(store.merge!(keys.zip(values), options)).to eq store
265
+ store.fetch_values('key1', 'key2', **options) { |k| "#{k} missing" }
233
266
  end
234
267
  end
268
+ let(:be_absent) { eq ['key1 missing', 'key2 missing'] }
235
269
 
236
- include_examples :updater_expiry
270
+ include_examples :loader_expiry
237
271
  end
238
272
 
239
- describe '#values_at' do
240
- let(:keys) { ['key1', 'key2'] }
241
- let(:values) { ['value1', 'value2'] }
273
+ context 'without default values given' do
242
274
  let(:loader) do
243
- lambda { |**options| store.values_at('key1', 'key2', **options) }
275
+ lambda do |**options|
276
+ store.fetch_values('key1', 'key2', **options)
277
+ end
244
278
  end
245
- let(:be_present) { eq ['value1', 'value2'] }
246
279
  let(:be_absent) { eq [nil, nil] }
247
280
 
248
281
  include_examples :loader_expiry
249
282
  end
283
+ end
250
284
 
251
- describe '#fetch_values' do
252
- let(:keys) { ['key1', 'key2'] }
253
- let(:values) { ['value1', 'value2'] }
254
- let(:be_present) { eq ['value1', 'value2'] }
255
-
256
- context 'with default values given via a block' do
257
- let(:loader) do
258
- lambda do |**options|
259
- store.fetch_values('key1', 'key2', **options) { |k| "#{k} missing" }
260
- end
261
- end
262
- let(:be_absent) { eq ['key1 missing', 'key2 missing'] }
263
-
264
- include_examples :loader_expiry
265
- end
266
-
267
- context 'without default values given' do
268
- let(:loader) do
269
- lambda do |**options|
270
- store.fetch_values('key1', 'key2', **options)
271
- end
272
- end
273
- let(:be_absent) { eq [nil, nil] }
274
-
275
- include_examples :loader_expiry
276
- end
285
+ describe '#slice' do
286
+ let(:keys) { ['key1', 'key2'] }
287
+ let(:values) { ['value1', 'value2'] }
288
+ let(:loader) do
289
+ lambda { |**options| store.slice('key1', 'key2', **options) }
277
290
  end
291
+ let(:be_present) { contain_exactly(['key1', 'value1'], ['key2', 'value2']) }
292
+ let(:be_absent) { be_empty }
278
293
 
279
- describe '#slice' do
280
- let(:keys) { ['key1', 'key2'] }
281
- let(:values) { ['value1', 'value2'] }
282
- let(:loader) do
283
- lambda { |**options| store.slice('key1', 'key2', **options) }
284
- end
285
- let(:be_present) { contain_exactly(['key1', 'value1'], ['key2', 'value2']) }
286
- let(:be_absent) { be_empty }
287
-
288
- include_examples :loader_expiry
289
- end
294
+ include_examples :loader_expiry
290
295
  end
291
296
  end