elephas 3.0.1 → 4.0.0
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/Gemfile +3 -3
- data/doc/Elephas/Backends/Base.html +5 -5
- data/doc/Elephas/Backends/Hash.html +19 -27
- data/doc/Elephas/Backends/RubyOnRails.html +10 -14
- data/doc/Elephas/Backends.html +5 -5
- data/doc/Elephas/Cache.html +23 -25
- data/doc/Elephas/Entry.html +35 -35
- data/doc/Elephas/Version.html +7 -7
- data/doc/Elephas.html +5 -5
- data/doc/_index.html +6 -6
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +5 -5
- data/doc/file_list.html +1 -1
- data/doc/frames.html +1 -1
- data/doc/index.html +5 -5
- data/doc/js/full_list.js +6 -1
- data/doc/method_list.html +35 -105
- data/doc/top-level-namespace.html +5 -5
- data/elephas.gemspec +1 -1
- data/lib/elephas/backends/base.rb +2 -2
- data/lib/elephas/backends/hash.rb +4 -6
- data/lib/elephas/backends/ruby_on_rails.rb +1 -3
- data/lib/elephas/cache.rb +7 -7
- data/lib/elephas/entry.rb +5 -5
- data/lib/elephas/version.rb +2 -2
- data/spec/elephas/cache_spec.rb +1 -1
- data/spec/elephas/entry_spec.rb +0 -1
- data/spec/elephas/providers/hash_spec.rb +1 -1
- data/spec/elephas/providers/ruby_on_rails_spec.rb +3 -3
- metadata +5 -5
data/doc/js/full_list.js
CHANGED
@@ -17,6 +17,7 @@ function fullListSearch() {
|
|
17
17
|
searchCache = [];
|
18
18
|
$('#full_list li').each(function() {
|
19
19
|
var link = $(this).find('.object_link a');
|
20
|
+
if (link.length === 0) return;
|
20
21
|
var fullName = link.attr('title').split(' ')[0];
|
21
22
|
searchCache.push({name:link.text(), fullName:fullName, node:$(this), link:link});
|
22
23
|
});
|
@@ -41,7 +42,7 @@ function fullListSearch() {
|
|
41
42
|
$('#full_list li').removeClass('found').each(function() {
|
42
43
|
|
43
44
|
var link = $(this).find('.object_link a');
|
44
|
-
link.text(link.text());
|
45
|
+
if (link.length > 0) link.text(link.text());
|
45
46
|
});
|
46
47
|
if (clicked) {
|
47
48
|
clicked.parents('ul').each(function() {
|
@@ -110,6 +111,10 @@ clicked = null;
|
|
110
111
|
function linkList() {
|
111
112
|
$('#full_list li, #full_list li a:last').click(function(evt) {
|
112
113
|
if ($(this).hasClass('toggle')) return true;
|
114
|
+
if ($(this).find('.object_link a').length === 0) {
|
115
|
+
$(this).children('a.toggle').click();
|
116
|
+
return false;
|
117
|
+
}
|
113
118
|
if (this.tagName.toLowerCase() == "li") {
|
114
119
|
var toggle = $(this).children('a.toggle');
|
115
120
|
if (toggle.size() > 0 && evt.pageX < toggle.offset().left) {
|
data/doc/method_list.html
CHANGED
@@ -48,281 +48,211 @@
|
|
48
48
|
|
49
49
|
<li class="r1 ">
|
50
50
|
<span class='object_link'><a href="Elephas/Entry.html#%3D%3D-instance_method" title="Elephas::Entry#== (method)">#==</a></span>
|
51
|
-
|
52
|
-
<small>Elephas::Entry</small>
|
53
|
-
|
51
|
+
<small>Elephas::Entry</small>
|
54
52
|
</li>
|
55
53
|
|
56
54
|
|
57
55
|
<li class="r2 ">
|
58
56
|
<span class='object_link'><a href="Elephas/Cache.html#backend-instance_method" title="Elephas::Cache#backend (method)">#backend</a></span>
|
59
|
-
|
60
|
-
<small>Elephas::Cache</small>
|
61
|
-
|
57
|
+
<small>Elephas::Cache</small>
|
62
58
|
</li>
|
63
59
|
|
64
60
|
|
65
61
|
<li class="r1 ">
|
66
62
|
<span class='object_link'><a href="Elephas/Backends/Hash.html#data-instance_method" title="Elephas::Backends::Hash#data (method)">#data</a></span>
|
67
|
-
|
68
|
-
<small>Elephas::Backends::Hash</small>
|
69
|
-
|
63
|
+
<small>Elephas::Backends::Hash</small>
|
70
64
|
</li>
|
71
65
|
|
72
66
|
|
73
67
|
<li class="r2 ">
|
74
68
|
<span class='object_link'><a href="Elephas/Backends/Base.html#delete-instance_method" title="Elephas::Backends::Base#delete (method)">#delete</a></span>
|
75
|
-
|
76
|
-
<small>Elephas::Backends::Base</small>
|
77
|
-
|
69
|
+
<small>Elephas::Backends::Base</small>
|
78
70
|
</li>
|
79
71
|
|
80
72
|
|
81
73
|
<li class="r1 ">
|
82
74
|
<span class='object_link'><a href="Elephas/Backends/RubyOnRails.html#delete-instance_method" title="Elephas::Backends::RubyOnRails#delete (method)">#delete</a></span>
|
83
|
-
|
84
|
-
<small>Elephas::Backends::RubyOnRails</small>
|
85
|
-
|
75
|
+
<small>Elephas::Backends::RubyOnRails</small>
|
86
76
|
</li>
|
87
77
|
|
88
78
|
|
89
79
|
<li class="r2 ">
|
90
80
|
<span class='object_link'><a href="Elephas/Cache.html#delete-instance_method" title="Elephas::Cache#delete (method)">#delete</a></span>
|
91
|
-
|
92
|
-
<small>Elephas::Cache</small>
|
93
|
-
|
81
|
+
<small>Elephas::Cache</small>
|
94
82
|
</li>
|
95
83
|
|
96
84
|
|
97
85
|
<li class="r1 ">
|
98
86
|
<span class='object_link'><a href="Elephas/Backends/Hash.html#delete-instance_method" title="Elephas::Backends::Hash#delete (method)">#delete</a></span>
|
99
|
-
|
100
|
-
<small>Elephas::Backends::Hash</small>
|
101
|
-
|
87
|
+
<small>Elephas::Backends::Hash</small>
|
102
88
|
</li>
|
103
89
|
|
104
90
|
|
105
91
|
<li class="r2 ">
|
106
92
|
<span class='object_link'><a href="Elephas/Entry.html#ensure-class_method" title="Elephas::Entry.ensure (method)">ensure</a></span>
|
107
|
-
|
108
|
-
<small>Elephas::Entry</small>
|
109
|
-
|
93
|
+
<small>Elephas::Entry</small>
|
110
94
|
</li>
|
111
95
|
|
112
96
|
|
113
97
|
<li class="r1 ">
|
114
98
|
<span class='object_link'><a href="Elephas/Backends/Base.html#exists%3F-instance_method" title="Elephas::Backends::Base#exists? (method)">#exists?</a></span>
|
115
|
-
|
116
|
-
<small>Elephas::Backends::Base</small>
|
117
|
-
|
99
|
+
<small>Elephas::Backends::Base</small>
|
118
100
|
</li>
|
119
101
|
|
120
102
|
|
121
103
|
<li class="r2 ">
|
122
104
|
<span class='object_link'><a href="Elephas/Backends/Hash.html#exists%3F-instance_method" title="Elephas::Backends::Hash#exists? (method)">#exists?</a></span>
|
123
|
-
|
124
|
-
<small>Elephas::Backends::Hash</small>
|
125
|
-
|
105
|
+
<small>Elephas::Backends::Hash</small>
|
126
106
|
</li>
|
127
107
|
|
128
108
|
|
129
109
|
<li class="r1 ">
|
130
110
|
<span class='object_link'><a href="Elephas/Cache.html#exists%3F-instance_method" title="Elephas::Cache#exists? (method)">#exists?</a></span>
|
131
|
-
|
132
|
-
<small>Elephas::Cache</small>
|
133
|
-
|
111
|
+
<small>Elephas::Cache</small>
|
134
112
|
</li>
|
135
113
|
|
136
114
|
|
137
115
|
<li class="r2 ">
|
138
116
|
<span class='object_link'><a href="Elephas/Backends/RubyOnRails.html#exists%3F-instance_method" title="Elephas::Backends::RubyOnRails#exists? (method)">#exists?</a></span>
|
139
|
-
|
140
|
-
<small>Elephas::Backends::RubyOnRails</small>
|
141
|
-
|
117
|
+
<small>Elephas::Backends::RubyOnRails</small>
|
142
118
|
</li>
|
143
119
|
|
144
120
|
|
145
121
|
<li class="r1 ">
|
146
122
|
<span class='object_link'><a href="Elephas/Entry.html#hash-instance_method" title="Elephas::Entry#hash (method)">#hash</a></span>
|
147
|
-
|
148
|
-
<small>Elephas::Entry</small>
|
149
|
-
|
123
|
+
<small>Elephas::Entry</small>
|
150
124
|
</li>
|
151
125
|
|
152
126
|
|
153
127
|
<li class="r2 ">
|
154
128
|
<span class='object_link'><a href="Elephas/Entry.html#hashify_key-class_method" title="Elephas::Entry.hashify_key (method)">hashify_key</a></span>
|
155
|
-
|
156
|
-
<small>Elephas::Entry</small>
|
157
|
-
|
129
|
+
<small>Elephas::Entry</small>
|
158
130
|
</li>
|
159
131
|
|
160
132
|
|
161
133
|
<li class="r1 ">
|
162
134
|
<span class='object_link'><a href="Elephas/Backends/Hash.html#initialize-instance_method" title="Elephas::Backends::Hash#initialize (method)">#initialize</a></span>
|
163
|
-
|
164
|
-
<small>Elephas::Backends::Hash</small>
|
165
|
-
|
135
|
+
<small>Elephas::Backends::Hash</small>
|
166
136
|
</li>
|
167
137
|
|
168
138
|
|
169
139
|
<li class="r2 ">
|
170
140
|
<span class='object_link'><a href="Elephas/Cache.html#initialize-instance_method" title="Elephas::Cache#initialize (method)">#initialize</a></span>
|
171
|
-
|
172
|
-
<small>Elephas::Cache</small>
|
173
|
-
|
141
|
+
<small>Elephas::Cache</small>
|
174
142
|
</li>
|
175
143
|
|
176
144
|
|
177
145
|
<li class="r1 ">
|
178
146
|
<span class='object_link'><a href="Elephas/Entry.html#initialize-instance_method" title="Elephas::Entry#initialize (method)">#initialize</a></span>
|
179
|
-
|
180
|
-
<small>Elephas::Entry</small>
|
181
|
-
|
147
|
+
<small>Elephas::Entry</small>
|
182
148
|
</li>
|
183
149
|
|
184
150
|
|
185
151
|
<li class="r2 ">
|
186
152
|
<span class='object_link'><a href="Elephas/Entry.html#key-instance_method" title="Elephas::Entry#key (method)">#key</a></span>
|
187
|
-
|
188
|
-
<small>Elephas::Entry</small>
|
189
|
-
|
153
|
+
<small>Elephas::Entry</small>
|
190
154
|
</li>
|
191
155
|
|
192
156
|
|
193
157
|
<li class="r1 ">
|
194
158
|
<span class='object_link'><a href="Elephas/Backends/Base.html#now-instance_method" title="Elephas::Backends::Base#now (method)">#now</a></span>
|
195
|
-
|
196
|
-
<small>Elephas::Backends::Base</small>
|
197
|
-
|
159
|
+
<small>Elephas::Backends::Base</small>
|
198
160
|
</li>
|
199
161
|
|
200
162
|
|
201
163
|
<li class="r2 ">
|
202
164
|
<span class='object_link'><a href="Elephas/Cache.html#prefix-instance_method" title="Elephas::Cache#prefix (method)">#prefix</a></span>
|
203
|
-
|
204
|
-
<small>Elephas::Cache</small>
|
205
|
-
|
165
|
+
<small>Elephas::Cache</small>
|
206
166
|
</li>
|
207
167
|
|
208
168
|
|
209
169
|
<li class="r1 ">
|
210
170
|
<span class='object_link'><a href="Elephas/Cache.html#read-instance_method" title="Elephas::Cache#read (method)">#read</a></span>
|
211
|
-
|
212
|
-
<small>Elephas::Cache</small>
|
213
|
-
|
171
|
+
<small>Elephas::Cache</small>
|
214
172
|
</li>
|
215
173
|
|
216
174
|
|
217
175
|
<li class="r2 ">
|
218
176
|
<span class='object_link'><a href="Elephas/Backends/RubyOnRails.html#read-instance_method" title="Elephas::Backends::RubyOnRails#read (method)">#read</a></span>
|
219
|
-
|
220
|
-
<small>Elephas::Backends::RubyOnRails</small>
|
221
|
-
|
177
|
+
<small>Elephas::Backends::RubyOnRails</small>
|
222
178
|
</li>
|
223
179
|
|
224
180
|
|
225
181
|
<li class="r1 ">
|
226
182
|
<span class='object_link'><a href="Elephas/Backends/Hash.html#read-instance_method" title="Elephas::Backends::Hash#read (method)">#read</a></span>
|
227
|
-
|
228
|
-
<small>Elephas::Backends::Hash</small>
|
229
|
-
|
183
|
+
<small>Elephas::Backends::Hash</small>
|
230
184
|
</li>
|
231
185
|
|
232
186
|
|
233
187
|
<li class="r2 ">
|
234
188
|
<span class='object_link'><a href="Elephas/Backends/Base.html#read-instance_method" title="Elephas::Backends::Base#read (method)">#read</a></span>
|
235
|
-
|
236
|
-
<small>Elephas::Backends::Base</small>
|
237
|
-
|
189
|
+
<small>Elephas::Backends::Base</small>
|
238
190
|
</li>
|
239
191
|
|
240
192
|
|
241
193
|
<li class="r1 ">
|
242
194
|
<span class='object_link'><a href="Elephas/Entry.html#refresh-instance_method" title="Elephas::Entry#refresh (method)">#refresh</a></span>
|
243
|
-
|
244
|
-
<small>Elephas::Entry</small>
|
245
|
-
|
195
|
+
<small>Elephas::Entry</small>
|
246
196
|
</li>
|
247
197
|
|
248
198
|
|
249
199
|
<li class="r2 ">
|
250
200
|
<span class='object_link'><a href="Elephas/Cache.html#setup_options-instance_method" title="Elephas::Cache#setup_options (method)">#setup_options</a></span>
|
251
|
-
|
252
|
-
<small>Elephas::Cache</small>
|
253
|
-
|
201
|
+
<small>Elephas::Cache</small>
|
254
202
|
</li>
|
255
203
|
|
256
204
|
|
257
205
|
<li class="r1 ">
|
258
206
|
<span class='object_link'><a href="Elephas/Entry.html#ttl-instance_method" title="Elephas::Entry#ttl (method)">#ttl</a></span>
|
259
|
-
|
260
|
-
<small>Elephas::Entry</small>
|
261
|
-
|
207
|
+
<small>Elephas::Entry</small>
|
262
208
|
</li>
|
263
209
|
|
264
210
|
|
265
211
|
<li class="r2 ">
|
266
212
|
<span class='object_link'><a href="Elephas/Entry.html#updated_at-instance_method" title="Elephas::Entry#updated_at (method)">#updated_at</a></span>
|
267
|
-
|
268
|
-
<small>Elephas::Entry</small>
|
269
|
-
|
213
|
+
<small>Elephas::Entry</small>
|
270
214
|
</li>
|
271
215
|
|
272
216
|
|
273
217
|
<li class="r1 ">
|
274
218
|
<span class='object_link'><a href="Elephas/Cache.html#use-instance_method" title="Elephas::Cache#use (method)">#use</a></span>
|
275
|
-
|
276
|
-
<small>Elephas::Cache</small>
|
277
|
-
|
219
|
+
<small>Elephas::Cache</small>
|
278
220
|
</li>
|
279
221
|
|
280
222
|
|
281
223
|
<li class="r2 ">
|
282
224
|
<span class='object_link'><a href="Elephas/Entry.html#valid%3F-instance_method" title="Elephas::Entry#valid? (method)">#valid?</a></span>
|
283
|
-
|
284
|
-
<small>Elephas::Entry</small>
|
285
|
-
|
225
|
+
<small>Elephas::Entry</small>
|
286
226
|
</li>
|
287
227
|
|
288
228
|
|
289
229
|
<li class="r1 ">
|
290
230
|
<span class='object_link'><a href="Elephas/Entry.html#value-instance_method" title="Elephas::Entry#value (method)">#value</a></span>
|
291
|
-
|
292
|
-
<small>Elephas::Entry</small>
|
293
|
-
|
231
|
+
<small>Elephas::Entry</small>
|
294
232
|
</li>
|
295
233
|
|
296
234
|
|
297
235
|
<li class="r2 ">
|
298
236
|
<span class='object_link'><a href="Elephas/Backends/Base.html#write-instance_method" title="Elephas::Backends::Base#write (method)">#write</a></span>
|
299
|
-
|
300
|
-
<small>Elephas::Backends::Base</small>
|
301
|
-
|
237
|
+
<small>Elephas::Backends::Base</small>
|
302
238
|
</li>
|
303
239
|
|
304
240
|
|
305
241
|
<li class="r1 ">
|
306
242
|
<span class='object_link'><a href="Elephas/Backends/RubyOnRails.html#write-instance_method" title="Elephas::Backends::RubyOnRails#write (method)">#write</a></span>
|
307
|
-
|
308
|
-
<small>Elephas::Backends::RubyOnRails</small>
|
309
|
-
|
243
|
+
<small>Elephas::Backends::RubyOnRails</small>
|
310
244
|
</li>
|
311
245
|
|
312
246
|
|
313
247
|
<li class="r2 ">
|
314
248
|
<span class='object_link'><a href="Elephas/Cache.html#write-instance_method" title="Elephas::Cache#write (method)">#write</a></span>
|
315
|
-
|
316
|
-
<small>Elephas::Cache</small>
|
317
|
-
|
249
|
+
<small>Elephas::Cache</small>
|
318
250
|
</li>
|
319
251
|
|
320
252
|
|
321
253
|
<li class="r1 ">
|
322
254
|
<span class='object_link'><a href="Elephas/Backends/Hash.html#write-instance_method" title="Elephas::Backends::Hash#write (method)">#write</a></span>
|
323
|
-
|
324
|
-
<small>Elephas::Backends::Hash</small>
|
325
|
-
|
255
|
+
<small>Elephas::Backends::Hash</small>
|
326
256
|
</li>
|
327
257
|
|
328
258
|
|
@@ -6,13 +6,13 @@
|
|
6
6
|
<title>
|
7
7
|
Top Level Namespace
|
8
8
|
|
9
|
-
— Documentation by YARD 0.8.
|
9
|
+
— Documentation by YARD 0.8.6.1
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
13
|
-
<link rel="stylesheet" href="css/style.css" type="text/css"
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
14
|
|
15
|
-
<link rel="stylesheet" href="css/common.css" type="text/css"
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
16
|
|
17
17
|
<script type="text/javascript" charset="utf-8">
|
18
18
|
hasFrames = window.top.frames.main ? true : false;
|
@@ -103,9 +103,9 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Sun May 19 15:44:47 2013 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
|
-
0.8.
|
108
|
+
0.8.6.1 (ruby-1.9.3).
|
109
109
|
</div>
|
110
110
|
|
111
111
|
</body>
|
data/elephas.gemspec
CHANGED
@@ -56,8 +56,8 @@ module Elephas
|
|
56
56
|
private
|
57
57
|
# Marks a method as unimplemented.
|
58
58
|
def unimplemented
|
59
|
-
|
60
|
-
raise ArgumentError.new(
|
59
|
+
i18n_setup(:elephas, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../../locales/")) if !@i18n
|
60
|
+
raise ArgumentError.new(i18n.unimplemented)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -9,7 +9,7 @@ module Elephas
|
|
9
9
|
# This is a simple backend, which uses an hash for storing the values.
|
10
10
|
#
|
11
11
|
# @attribute data
|
12
|
-
# @return [
|
12
|
+
# @return [HashWithIndifferentAccess] The internal hash used by the backend.
|
13
13
|
class Hash < Base
|
14
14
|
attr_accessor :data
|
15
15
|
|
@@ -17,7 +17,7 @@ module Elephas
|
|
17
17
|
#
|
18
18
|
# @param data [Hash] The initial data stored.
|
19
19
|
def initialize(data = nil)
|
20
|
-
@data = data
|
20
|
+
@data = data.ensure_hash({}).with_indifferent_access
|
21
21
|
end
|
22
22
|
|
23
23
|
# Reads a value from the cache.
|
@@ -25,7 +25,7 @@ module Elephas
|
|
25
25
|
# @param key [String] The key to lookup.
|
26
26
|
# @return [Entry|NilClass] The read value or `nil`.
|
27
27
|
def read(key)
|
28
|
-
|
28
|
+
exists?(key) ? @data[key] : nil
|
29
29
|
end
|
30
30
|
|
31
31
|
# Writes a value to the cache.
|
@@ -38,7 +38,7 @@ module Elephas
|
|
38
38
|
def write(key, value, options = {})
|
39
39
|
entry = ::Elephas::Entry.ensure(value, key, options)
|
40
40
|
entry.refresh
|
41
|
-
@data[key
|
41
|
+
@data[key] = entry
|
42
42
|
entry
|
43
43
|
end
|
44
44
|
|
@@ -47,7 +47,6 @@ module Elephas
|
|
47
47
|
# @param key [String] The key to delete.
|
48
48
|
# @return [Boolean] `true` if the key was in the cache, `false` otherwise.
|
49
49
|
def delete(key)
|
50
|
-
key = key.ensure_string
|
51
50
|
rv = @data.has_key?(key)
|
52
51
|
@data.delete(key)
|
53
52
|
rv
|
@@ -58,7 +57,6 @@ module Elephas
|
|
58
57
|
# @param key [String] The key to lookup.
|
59
58
|
# @return [Boolean] `true` if the key is in the cache, `false` otherwise.
|
60
59
|
def exists?(key)
|
61
|
-
key = key.ensure_string
|
62
60
|
@data.has_key?(key) && @data[key].valid?(self)
|
63
61
|
end
|
64
62
|
end
|
@@ -13,7 +13,7 @@ module Elephas
|
|
13
13
|
# @param key [String] The key to lookup.
|
14
14
|
# @return [Entry|NilClass] The read value or `nil`.
|
15
15
|
def read(key)
|
16
|
-
|
16
|
+
exists?(key) ? Rails.cache.read(key) : nil
|
17
17
|
end
|
18
18
|
|
19
19
|
# Writes a value to the cache.
|
@@ -35,7 +35,6 @@ module Elephas
|
|
35
35
|
# @param key [String] The key to delete.
|
36
36
|
# @return [Boolean] `true` if the key was in the cache, `false` otherwise.
|
37
37
|
def delete(key)
|
38
|
-
key = key.ensure_string
|
39
38
|
rv = Rails.cache.exist?(key)
|
40
39
|
Rails.cache.delete(key)
|
41
40
|
rv
|
@@ -46,7 +45,6 @@ module Elephas
|
|
46
45
|
# @param key [String] The key to lookup.
|
47
46
|
# @return [Boolean] `true` if the key is in the cache, `false` otherwise.
|
48
47
|
def exists?(key)
|
49
|
-
key = key.ensure_string
|
50
48
|
Rails.cache.exist?(key) && Rails.cache.read(key).valid?(self)
|
51
49
|
end
|
52
50
|
end
|
data/lib/elephas/cache.rb
CHANGED
@@ -56,7 +56,7 @@ module Elephas
|
|
56
56
|
rv = nil
|
57
57
|
|
58
58
|
# Get options
|
59
|
-
options =
|
59
|
+
options = setup_options(options, key)
|
60
60
|
|
61
61
|
# Check if the storage has the value (if we don't have to skip the cache)
|
62
62
|
rv = choose_backend(options).read(options[:hash]) if options[:force] == false && options[:ttl] > 0
|
@@ -83,7 +83,7 @@ module Elephas
|
|
83
83
|
# @see .setup_options
|
84
84
|
# @return [Object] The value itself.
|
85
85
|
def write(key, value, options = {})
|
86
|
-
choose_backend(options).write(key, value,
|
86
|
+
choose_backend(options).write(key, value, setup_options(options, key))
|
87
87
|
end
|
88
88
|
|
89
89
|
# Deletes a value from the cache.
|
@@ -119,8 +119,7 @@ module Elephas
|
|
119
119
|
# @param key [String] The key to associate to this options.
|
120
120
|
# @return [Hash] An options hash.
|
121
121
|
def setup_options(options, key)
|
122
|
-
options = {
|
123
|
-
options = {ttl: 1.hour * 1000, force: false, as_entry: false}.merge(options)
|
122
|
+
options = {ttl: 1.hour * 1000, force: false, as_entry: false}.merge(options.ensure_hash({}))
|
124
123
|
|
125
124
|
# Sanitize options.
|
126
125
|
options = sanitize_options(options, key)
|
@@ -143,7 +142,7 @@ module Elephas
|
|
143
142
|
def compute_value(options, &block)
|
144
143
|
rv = block.call(options)
|
145
144
|
rv = ::Elephas::Entry.ensure(rv, options[:complete_key], options) # Make sure is an entry
|
146
|
-
|
145
|
+
write(rv.hash, rv, options) if !rv.value.nil? && options[:ttl] > 0 # We have a value and we have to store it
|
147
146
|
rv
|
148
147
|
end
|
149
148
|
|
@@ -153,10 +152,11 @@ module Elephas
|
|
153
152
|
# @param key [String] The key to associate to this options.
|
154
153
|
# @return [Hash] An options hash.
|
155
154
|
def sanitize_options(options, key)
|
156
|
-
options[:key] ||= key
|
155
|
+
options[:key] ||= key
|
157
156
|
options[:ttl] == options[:ttl].blank? ? 1.hour * 1000 : [options[:ttl].to_integer, 0].max
|
158
157
|
options[:force] = options[:force].to_boolean
|
159
158
|
options[:prefix] = options[:prefix].present? ? options[:prefix] : self.prefix
|
159
|
+
|
160
160
|
options
|
161
161
|
end
|
162
162
|
|
@@ -164,7 +164,7 @@ module Elephas
|
|
164
164
|
#
|
165
165
|
# @param options [Backends::Base|Hash] The backend to use. Defaults to the current backend.
|
166
166
|
def choose_backend(options)
|
167
|
-
backend =
|
167
|
+
backend = options.ensure_hash({}).symbolize_keys[:backend]
|
168
168
|
backend.is_a?(Elephas::Backends::Base) ? backend : self.backend
|
169
169
|
end
|
170
170
|
end
|
data/lib/elephas/entry.rb
CHANGED
@@ -35,7 +35,7 @@ module Elephas
|
|
35
35
|
@hash = hash.present? ? hash : self.class.hashify_key(key)
|
36
36
|
@value = value
|
37
37
|
@ttl = ttl
|
38
|
-
|
38
|
+
refresh
|
39
39
|
end
|
40
40
|
|
41
41
|
# Refreshes the entry.
|
@@ -54,7 +54,7 @@ module Elephas
|
|
54
54
|
# @param backend [Backends::Base] The backend to use for the check.
|
55
55
|
# @return [Boolean] `true` if the entry is still valid, `false` otherwise.
|
56
56
|
def valid?(backend)
|
57
|
-
backend.now -
|
57
|
+
backend.now - updated_at < self.ttl / 1000
|
58
58
|
end
|
59
59
|
|
60
60
|
# Compares to another Entry.
|
@@ -70,7 +70,7 @@ module Elephas
|
|
70
70
|
# @param key [String] The key to hashify.
|
71
71
|
# @return [String] An unique hash for the key.
|
72
72
|
def self.hashify_key(key)
|
73
|
-
Digest::SHA2.hexdigest(key
|
73
|
+
Digest::SHA2.hexdigest(key)
|
74
74
|
end
|
75
75
|
|
76
76
|
# Ensures that the value is an Entry.
|
@@ -83,10 +83,10 @@ module Elephas
|
|
83
83
|
rv = value
|
84
84
|
|
85
85
|
if !rv.is_a?(::Elephas::Entry) then
|
86
|
-
options =
|
86
|
+
options = options.ensure_hash({})
|
87
87
|
|
88
88
|
ttl = [options[:ttl].to_integer, 0].max
|
89
|
-
hash = options[:hash] || ::Elephas::Entry.hashify_key(key
|
89
|
+
hash = options[:hash] || ::Elephas::Entry.hashify_key(key)
|
90
90
|
|
91
91
|
rv = ::Elephas::Entry.new(key, rv, hash, ttl)
|
92
92
|
end
|
data/lib/elephas/version.rb
CHANGED
@@ -11,13 +11,13 @@ module Elephas
|
|
11
11
|
# @see http://semver.org
|
12
12
|
module Version
|
13
13
|
# The major version.
|
14
|
-
MAJOR =
|
14
|
+
MAJOR = 4
|
15
15
|
|
16
16
|
# The minor version.
|
17
17
|
MINOR = 0
|
18
18
|
|
19
19
|
# The patch version.
|
20
|
-
PATCH =
|
20
|
+
PATCH = 0
|
21
21
|
|
22
22
|
# The current version of elephas.
|
23
23
|
STRING = [MAJOR, MINOR, PATCH].compact.join(".")
|
data/spec/elephas/cache_spec.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
require "spec_helper"
|
8
8
|
|
9
|
-
describe
|
9
|
+
describe Elephas::Cache do
|
10
10
|
let(:entry) { ::Elephas::Entry.ensure("VALUE", ::Elephas::Cache.new(nil).prefix + "[KEY]", {ttl: 3600}) }
|
11
11
|
let(:reference) { ::Elephas::Cache.new(::Elephas::Backends::Hash.new) }
|
12
12
|
|
data/spec/elephas/entry_spec.rb
CHANGED
@@ -84,7 +84,6 @@ describe Elephas::Entry do
|
|
84
84
|
it "should compute a good hash" do
|
85
85
|
expect(::Elephas::Entry.hashify_key("HASH 1")).to eq("88e1f3572122e2605c1fab09efa8d4e99f5a064ae0230ca0aeced839796aba35")
|
86
86
|
expect(::Elephas::Entry.hashify_key("HASH 2")).to eq("38589cee32e00f700cf958dfe98f17d6da231700c41586e3c32b00314bb3cb58")
|
87
|
-
expect(::Elephas::Entry.hashify_key(nil)).to eq("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
|
88
87
|
end
|
89
88
|
end
|
90
89
|
|
@@ -16,7 +16,7 @@ describe Elephas::Backends::Hash do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should create a store with an given hash" do
|
19
|
-
expect(::Elephas::Backends::Hash.new({a: :b}).data).to eq({a
|
19
|
+
expect(::Elephas::Backends::Hash.new({a: :b}).data).to eq({"a" => :b})
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should ensure that the store is an Hash" do
|
@@ -12,13 +12,13 @@ describe Elephas::Backends::RubyOnRails do
|
|
12
12
|
self[key]
|
13
13
|
end
|
14
14
|
|
15
|
-
def write(key, value,
|
16
|
-
|
15
|
+
def write(key, value, _)
|
16
|
+
delete(key)
|
17
17
|
self[key] = value
|
18
18
|
end
|
19
19
|
|
20
20
|
def exist?(key)
|
21
|
-
|
21
|
+
has_key?(key)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|