activerecord-reactor 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG +5 -0
- data/lib/active_record/reactor.rb +14 -3
- data/lib/active_record/reactor/version.rb +1 -1
- data/test/cases/reactor_test.rb +24 -2
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4fb857e4ea5416ec633effb7cc11376981c68f0acb2b49257975c7ea3bcfa2dd
|
4
|
+
data.tar.gz: 50906b950e0ce055085ba19a9ced733b56484740fb0ebece508d3dba76c1ee02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68c64d41ab78c4f3e09baf704916e5ebecb6a7deb98f2bbd1d44cc78809883e55e59c5067deff6abc168c90a818c9f016fe987478cfd1f5fd2dd33800aef755f
|
7
|
+
data.tar.gz: 7a6812c14dc95f0c9b6734e633a1f78e77e4118c118be2963ddef7a33a98965ef30c02e4a3f5429364ba91c17eb9f44f3a862cdc9a246c636d0cf81ede456803
|
data/CHANGELOG
CHANGED
@@ -45,6 +45,7 @@ module ActiveRecord
|
|
45
45
|
include Singleton
|
46
46
|
|
47
47
|
class << self
|
48
|
+
|
48
49
|
def callbacks # :nodoc:
|
49
50
|
(self.public_instance_methods - ActiveRecord::Reactor.public_instance_methods).grep(/\A(before|around|after)_.+/)
|
50
51
|
end
|
@@ -55,12 +56,22 @@ module ActiveRecord
|
|
55
56
|
|
56
57
|
# Stops all reactions while inside the (required) block.
|
57
58
|
def scram(&block)
|
58
|
-
previously_scrammed =
|
59
|
-
|
59
|
+
previously_scrammed = nil
|
60
|
+
mutex.synchronize do
|
61
|
+
previously_scrammed = @scrammed
|
62
|
+
@scrammed = true
|
63
|
+
end
|
60
64
|
yield
|
61
65
|
ensure
|
62
|
-
@scrammed = previously_scrammed
|
66
|
+
mutex.synchronize { @scrammed = previously_scrammed }
|
63
67
|
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def mutex
|
72
|
+
@mutex ||= Mutex.new
|
73
|
+
end
|
74
|
+
|
64
75
|
end
|
65
76
|
end
|
66
77
|
|
data/test/cases/reactor_test.rb
CHANGED
@@ -26,10 +26,32 @@ class ReactorTest < ActiveSupport::TestCase
|
|
26
26
|
|
27
27
|
test 'Scrammed reactors do not react' do
|
28
28
|
FruitReactor.scram do
|
29
|
-
|
30
|
-
|
29
|
+
Banana.create(color: 'blue')
|
30
|
+
Cherry.create(color: 'red')
|
31
31
|
end
|
32
32
|
assert_empty FruitReactor.calls
|
33
33
|
assert_equal false, FruitReactor.scrammed?
|
34
34
|
end
|
35
|
+
|
36
|
+
test 'Subclasses have their own mutex' do
|
37
|
+
fruit_mutex = FruitReactor.send(:mutex)
|
38
|
+
peel_mutex = PeelReactor.send(:mutex)
|
39
|
+
assert_kind_of Mutex, fruit_mutex
|
40
|
+
assert_kind_of Mutex, peel_mutex
|
41
|
+
assert_not_equal fruit_mutex.object_id, peel_mutex.object_id
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'Threading' do
|
45
|
+
threads = 5.times.collect do
|
46
|
+
Thread.new do
|
47
|
+
100_000.times do
|
48
|
+
FruitReactor.scram do
|
49
|
+
#
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
threads.each(&:join)
|
55
|
+
assert_equal false, FruitReactor.scrammed?
|
56
|
+
end
|
35
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-reactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sqlite3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
|
-
|
112
|
-
rubygems_version: 2.5.1
|
111
|
+
rubygems_version: 3.0.3
|
113
112
|
signing_key:
|
114
113
|
specification_version: 4
|
115
114
|
summary: Controlled reactions on ActiveRecord callbacks
|