request_store 1.0.8 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/request_store.rb +36 -32
- data/lib/request_store/version.rb +1 -1
- data/test/request_store_test.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f85cc719e97b2fd7d14f66225abf332e8f6a1248
|
4
|
+
data.tar.gz: 8b850f88cdaff14f6150e8799a931d85935402e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6628a9dbf581592b306082f4782d44c0577b34eea89dbe3d231ece2b069a7b8b5b51dc9a6993df058dd989aeeda2a26e7dc35f5d7ca0f8353cbc1a918502322f
|
7
|
+
data.tar.gz: d18615c3d9a6cd02bea10a119b549690d15cf87fbb0e9b3d62947ce7d004e55952124f5f7172a404b976bdaa7e2659ba135fca6ecc92563084d3edc3451d39df
|
data/lib/request_store.rb
CHANGED
@@ -3,36 +3,40 @@ require "request_store/middleware"
|
|
3
3
|
require "request_store/railtie" if defined?(Rails::Railtie)
|
4
4
|
|
5
5
|
module RequestStore
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
6
|
+
def self.store
|
7
|
+
Thread.current[:request_store] ||= {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.clear!
|
11
|
+
Thread.current[:request_store] = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.read(key)
|
15
|
+
store[key]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.[](key)
|
19
|
+
store[key]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.write(key, value)
|
23
|
+
store[key] = value
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.[]=(key, value)
|
27
|
+
store[key] = value
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.exist?(key)
|
31
|
+
store.key?(key)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.fetch(key, &block)
|
35
|
+
store[key] = yield unless exist?(key)
|
36
|
+
store[key]
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.delete(key, &block)
|
40
|
+
store.delete(key, &block)
|
41
|
+
end
|
38
42
|
end
|
data/test/request_store_test.rb
CHANGED
@@ -48,6 +48,13 @@ class RequestStoreTest < Minitest::Unit::TestCase
|
|
48
48
|
assert_equal 2, RequestStore.fetch(:foo) { 2 + 2 }
|
49
49
|
end
|
50
50
|
|
51
|
+
def test_delete
|
52
|
+
RequestStore.clear!
|
53
|
+
assert_equal 2, RequestStore.fetch(:foo) { 1 + 1 }
|
54
|
+
assert_equal 2, RequestStore.delete(:foo) { 2 + 2 }
|
55
|
+
assert_equal 4, RequestStore.delete(:foo) { 2 + 2 }
|
56
|
+
end
|
57
|
+
|
51
58
|
def test_delegates_to_thread
|
52
59
|
RequestStore.clear!
|
53
60
|
RequestStore.store[:foo] = 1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: request_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Klabnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|