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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb3e17b4e4c29fdf633fdbe9cbd51424d62ef77b
4
- data.tar.gz: c8f310a093f800910a9cb961155fcec3b5566b10
3
+ metadata.gz: f85cc719e97b2fd7d14f66225abf332e8f6a1248
4
+ data.tar.gz: 8b850f88cdaff14f6150e8799a931d85935402e6
5
5
  SHA512:
6
- metadata.gz: fb37f222f196d1e72b349d771795e89ef98dbd060953318ff3cce18484aae33b1e8babd44a9fe4698aa00fe4d35d2e82c60f7fc2302491ae4b71a7e2620ced50
7
- data.tar.gz: 9cc43fe801adab0f1f6c5085aeb94646f189e5fe4631d6a583b78bc6708904879fee2742a7e3338e6c0d3c51e1dbed97245a9a558db44d445f1881be679a4103
6
+ metadata.gz: 6628a9dbf581592b306082f4782d44c0577b34eea89dbe3d231ece2b069a7b8b5b51dc9a6993df058dd989aeeda2a26e7dc35f5d7ca0f8353cbc1a918502322f
7
+ data.tar.gz: d18615c3d9a6cd02bea10a119b549690d15cf87fbb0e9b3d62947ce7d004e55952124f5f7172a404b976bdaa7e2659ba135fca6ecc92563084d3edc3451d39df
@@ -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
- 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
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
@@ -1,3 +1,3 @@
1
1
  module RequestStore
2
- VERSION = "1.0.8"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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.8
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-07-28 00:00:00.000000000 Z
11
+ date: 2014-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake