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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5af5bf8ba7a0f8015fc807306996064bb5aae71e
4
- data.tar.gz: 079bd7c5e25c9aec35736ef010e3a281108723f2
2
+ SHA256:
3
+ metadata.gz: 4fb857e4ea5416ec633effb7cc11376981c68f0acb2b49257975c7ea3bcfa2dd
4
+ data.tar.gz: 50906b950e0ce055085ba19a9ced733b56484740fb0ebece508d3dba76c1ee02
5
5
  SHA512:
6
- metadata.gz: 8f155aefc6aa6f0ccfe029604237d97d558759fe9aad71522bcd87181329a8c8a2d0d8dc98b666af81ff93de9ea4dc1ae673a0a63c4fc8fca8e944edda87f3e5
7
- data.tar.gz: 92b05135c408e08a6a10bf19a95bb549d1f3b04be618d35222b5ca6e8870a275239470db0a4b15a4407d5b2db7b5140946da2d731b1e7ba670099d796bcbfb87
6
+ metadata.gz: 68c64d41ab78c4f3e09baf704916e5ebecb6a7deb98f2bbd1d44cc78809883e55e59c5067deff6abc168c90a818c9f016fe987478cfd1f5fd2dd33800aef755f
7
+ data.tar.gz: 7a6812c14dc95f0c9b6734e633a1f78e77e4118c118be2963ddef7a33a98965ef30c02e4a3f5429364ba91c17eb9f44f3a862cdc9a246c636d0cf81ede456803
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 1.5.0
2
+
3
+ Support Rails 6
4
+ Make threadsafe
5
+
1
6
  1.0.1
2
7
 
3
8
  Remove incorrect class definitions
@@ -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 = @scrammed
59
- @scrammed = true
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
 
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  class Reactor
3
- VERSION = '1.4.0'
3
+ VERSION = '1.5.0'
4
4
  end
5
5
  end
@@ -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
- b = Banana.create(color: 'blue')
30
- c = Cherry.create(color: 'red')
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.0
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: 2018-04-16 00:00:00.000000000 Z
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: 5.2.0
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: 5.2.0
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
- rubyforge_project:
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