request_store 1.5.0 → 1.5.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4940fb899c4f08b98633877ca272f29dcdd4ade30456bc87a2529d38da9385e8
4
- data.tar.gz: 8be86e88c85f7aeaa3b0ac1eee98da6b26f9c95595319fc010eb800e542eb3cf
3
+ metadata.gz: a8829219a616f7288e08e65fe5d39d491b1693cb31ca5632355a4a4216167a21
4
+ data.tar.gz: 1f151729fdffa5b98422b359ab3f145caf8a19943bb075f0b5d2b13999b318b3
5
5
  SHA512:
6
- metadata.gz: 59f193bbe4aaa3e1a13d5540840b379eadfd654f3f30ac5c9f8dcd780357f0fcc88a2a70d85f3637934a9eff9297cf4d410ceb2829a8ccdc2f6c9cf0631d1579
7
- data.tar.gz: 1727397fd735206c9260e5957a78ec9014966619024e7083d29e5ccab5b71178794a2aa1892f0801bbd4afd267a2b7a3b75728a0fc086d0575be2ac477040501
6
+ metadata.gz: bc75042c21655c31f3392520e49a7bc816a157a5ac60ba783b73436d5293b88379ac08c0dc94ba352b7f4819c6d48cebccd60315a930a1d600c2a65148f14ae8
7
+ data.tar.gz: d70cb3dbb0868d4311cdb1ff6b710c9bab96c698acdd0d6d4c409ea133dafe119a43bd9d1eee41eea819350e5187aa4338fb4fda3d69613d6a128f9cbd86c7ea
data/.travis.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  language: ruby
2
- sudo: false
3
2
  rvm:
4
3
  - 1.9.3
5
4
  - 2.0.0
@@ -12,6 +11,7 @@ rvm:
12
11
  - jruby-19mode
13
12
  - ruby-head
14
13
  - jruby-head
14
+ - truffleruby-head
15
15
  matrix:
16
16
  allow_failures:
17
17
  - rvm: ruby-head
data/README.md CHANGED
@@ -58,6 +58,16 @@ Yep, everywhere you used `Thread.current` just change it to
58
58
  `RequestStore.store`. Now no matter what server you use, you'll get `1` every
59
59
  time: the storage is local to that request.
60
60
 
61
+ ### API
62
+
63
+ The `fetch` method returns the stored value if it already exists. If no stored value exists, it uses the provided block to add a new stored value.
64
+
65
+ ```ruby
66
+ top_posts = RequestStore.fetch(:top_posts) do
67
+ # code to obtain the top posts
68
+ end
69
+ ```
70
+
61
71
  ### Rails 2 compatibility
62
72
 
63
73
  The gem includes a Railtie that will configure everything properly for Rails 3+
@@ -16,12 +16,16 @@ module RequestStore
16
16
  def call(env)
17
17
  RequestStore.begin!
18
18
 
19
- response = @app.call(env)
19
+ status, headers, body = @app.call(env)
20
20
 
21
- returned = response << Rack::BodyProxy.new(response.pop) do
21
+ body = Rack::BodyProxy.new(body) do
22
22
  RequestStore.end!
23
23
  RequestStore.clear!
24
24
  end
25
+
26
+ returned = true
27
+
28
+ [status, headers, body]
25
29
  ensure
26
30
  unless returned
27
31
  RequestStore.end!
@@ -1,3 +1,3 @@
1
1
  module RequestStore
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.1"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["steve@steveklabnik.com"]
11
11
  gem.description = %q{RequestStore gives you per-request global storage.}
12
12
  gem.summary = %q{RequestStore gives you per-request global storage.}
13
- gem.homepage = "http://github.com/steveklabnik/request_store"
13
+ gem.homepage = "https://github.com/steveklabnik/request_store"
14
14
  gem.licenses = ["MIT"]
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
@@ -12,6 +12,7 @@ class MiddlewareTest < Minitest::Test
12
12
  def call_middleware(opts = {})
13
13
  _, _, proxy = @middleware.call(opts)
14
14
  proxy.close
15
+ proxy
15
16
  end
16
17
 
17
18
  def test_middleware_resets_store
@@ -23,6 +24,17 @@ class MiddlewareTest < Minitest::Test
23
24
  assert_equal({}, RequestStore.store)
24
25
  end
25
26
 
27
+ def test_middleware_does_not_mutate_response_and_does_not_overflow_stack
28
+ 10000.times do
29
+ call_middleware
30
+ end
31
+
32
+ resp = call_middleware
33
+ assert resp.is_a?(::Rack::BodyProxy)
34
+ assert_equal ["response"], resp.to_a
35
+ assert_equal ["response"], resp.instance_variable_get(:@body)
36
+ end
37
+
26
38
  def test_middleware_resets_store_on_error
27
39
  e = assert_raises RuntimeError do
28
40
  call_middleware({:error => true})
@@ -63,3 +75,27 @@ class MiddlewareTest < Minitest::Test
63
75
  refute RequestStore.store[:foo]
64
76
  end
65
77
  end
78
+
79
+ class MiddlewareWithConstResponseTest < Minitest::Test
80
+ def setup
81
+ @app = RackAppWithConstResponse.new
82
+ @middleware = RequestStore::Middleware.new(@app)
83
+ end
84
+
85
+ def call_middleware(opts = {})
86
+ _, _, proxy = @middleware.call(opts)
87
+ proxy.close
88
+ proxy
89
+ end
90
+
91
+ def test_middleware_does_not_mutate_response_and_does_not_overflow_stack
92
+ 10000.times do
93
+ call_middleware
94
+ end
95
+
96
+ resp = call_middleware
97
+ assert resp.is_a?(::Rack::BodyProxy)
98
+ assert_equal ["response"], resp.to_a
99
+ assert_equal ["response"], resp.instance_variable_get(:@body)
100
+ end
101
+ end
data/test/test_helper.rb CHANGED
@@ -11,3 +11,19 @@ class RackApp
11
11
  [200, {}, ["response"]]
12
12
  end
13
13
  end
14
+
15
+ class RackAppWithConstResponse
16
+ RESPONSE = [200, {}, ["response"]]
17
+
18
+ attr_reader :last_value, :store_active
19
+
20
+ def call(env)
21
+ RequestStore.store[:foo] ||= 0
22
+ RequestStore.store[:foo] += 1
23
+ @last_value = RequestStore.store[:foo]
24
+ @store_active = RequestStore.active?
25
+ raise 'FAIL' if env[:error]
26
+
27
+ RESPONSE
28
+ end
29
+ end
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.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Klabnik
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-20 00:00:00.000000000 Z
11
+ date: 2022-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -73,11 +73,11 @@ files:
73
73
  - test/middleware_test.rb
74
74
  - test/request_store_test.rb
75
75
  - test/test_helper.rb
76
- homepage: http://github.com/steveklabnik/request_store
76
+ homepage: https://github.com/steveklabnik/request_store
77
77
  licenses:
78
78
  - MIT
79
79
  metadata: {}
80
- post_install_message:
80
+ post_install_message:
81
81
  rdoc_options: []
82
82
  require_paths:
83
83
  - lib
@@ -92,8 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  requirements: []
95
- rubygems_version: 3.0.3
96
- signing_key:
95
+ rubygems_version: 3.2.15
96
+ signing_key:
97
97
  specification_version: 4
98
98
  summary: RequestStore gives you per-request global storage.
99
99
  test_files: