request_store 1.2.1 → 1.3.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: 0f330736e888660271d908162a43f5a277ac12f9
4
- data.tar.gz: ceb6fb78c39700c7647fe94a52275941f9aeb16b
3
+ metadata.gz: 743e2b453797cff390b0811b3f0f4fb13eebf15a
4
+ data.tar.gz: 00809cfc84d6a74f4358c63445403f42d938b2d5
5
5
  SHA512:
6
- metadata.gz: 5389ea2f73f3324cfaf1cd05866fd2d025a153c98d17b6aa0011ec86631b5b21582bc52cacf6089f64d0445c2af6524ab80bbb4dbad2727930cbd341cde25128
7
- data.tar.gz: ff40c52f1ca83f3503ee0703c5298508f3b4c6cc5f4a349c37aff8b71b8c336c34109f93afb8b69be4d9b0a2b7ffdc975ca59d7a710ad3db7208c7e98e5d0142
6
+ metadata.gz: 2682121838ae3862866cf8a65e76d12d34010cc89a2d7a5f89fe42531670ec2a40bba9647503d14f6906619c84a74f1c6483bdd7f09096521b93aceff2f537c0
7
+ data.tar.gz: 50eef4bb4582b09c1a9c20aa74614213cb8d3e24602804f84efb52b3adc01e0c8c5c9924e2d93c20eff4a533dac8d8d017ece682e3134e68270fc9491215ba47
@@ -11,6 +11,18 @@ module RequestStore
11
11
  Thread.current[:request_store] = {}
12
12
  end
13
13
 
14
+ def self.begin!
15
+ Thread.current[:request_store_active] = true
16
+ end
17
+
18
+ def self.end!
19
+ Thread.current[:request_store_active] = false
20
+ end
21
+
22
+ def self.active?
23
+ Thread.current[:request_store_active] || false
24
+ end
25
+
14
26
  def self.read(key)
15
27
  store[key]
16
28
  end
@@ -5,8 +5,10 @@ module RequestStore
5
5
  end
6
6
 
7
7
  def call(env)
8
+ RequestStore.begin!
8
9
  @app.call(env)
9
10
  ensure
11
+ RequestStore.end!
10
12
  RequestStore.clear!
11
13
  end
12
14
  end
@@ -1,3 +1,3 @@
1
1
  module RequestStore
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -24,4 +24,22 @@ class MiddlewareTest < Minitest::Test
24
24
  assert_equal 'FAIL', e.message
25
25
  assert_equal({}, RequestStore.store)
26
26
  end
27
+
28
+ def test_middleware_begins_store
29
+ @middleware.call({})
30
+ assert_equal true, @app.store_active
31
+ end
32
+
33
+ def test_middleware_ends_store
34
+ @middleware.call({})
35
+ assert_equal false, RequestStore.active?
36
+ end
37
+
38
+ def test_middleware_ends_store_on_error
39
+ assert_raises RuntimeError do
40
+ @middleware.call({:error => true})
41
+ end
42
+
43
+ assert_equal false, RequestStore.active?
44
+ end
27
45
  end
@@ -56,4 +56,14 @@ class RequestStoreTest < Minitest::Test
56
56
  RequestStore.store[:foo] = 1
57
57
  assert_equal 1, Thread.current[:request_store][:foo]
58
58
  end
59
+
60
+ def test_active_state
61
+ assert_equal false, RequestStore.active?
62
+
63
+ RequestStore.begin!
64
+ assert_equal true, RequestStore.active?
65
+
66
+ RequestStore.end!
67
+ assert_equal false, RequestStore.active?
68
+ end
59
69
  end
@@ -1,10 +1,11 @@
1
1
  class RackApp
2
- attr_reader :last_value
2
+ attr_reader :last_value, :store_active
3
3
 
4
4
  def call(env)
5
5
  RequestStore.store[:foo] ||= 0
6
6
  RequestStore.store[:foo] += 1
7
7
  @last_value = RequestStore.store[:foo]
8
+ @store_active = RequestStore.active?
8
9
  raise 'FAIL' if env[:error]
9
10
  end
10
11
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.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: 2015-11-19 00:00:00.000000000 Z
11
+ date: 2016-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '5.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.0'
41
41
  description: RequestStore gives you per-request global storage.
@@ -45,8 +45,8 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - ".gitignore"
49
- - ".travis.yml"
48
+ - .gitignore
49
+ - .travis.yml
50
50
  - Gemfile
51
51
  - LICENSE.txt
52
52
  - README.md
@@ -69,17 +69,17 @@ require_paths:
69
69
  - lib
70
70
  required_ruby_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ">="
72
+ - - '>='
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - ">="
77
+ - - '>='
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.4.8
82
+ rubygems_version: 2.0.14.1
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: RequestStore gives you per-request global storage.