abstractivator 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/abstractivator.gemspec +1 -0
- data/lib/abstractivator/fiber_defer.rb +10 -0
- data/lib/abstractivator/version.rb +1 -1
- data/spec/lib/abstractivator/fiber_defer_spec.rb +27 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3ef0c368cb253c8c08111f0a204a41efd75e771
|
4
|
+
data.tar.gz: 35e867d02a3f1ab5f98597eed4f33b8f608cf1ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3c36e1d70be6effe19a3cc00ed630f24a53f7e3f3d2052a29c6ab3b285bfbf7d25301ad6d052c4626af50389f1555ebcd5bf5ae783bd34f7666727c2743760d
|
7
|
+
data.tar.gz: 553330854e53ce6027e804119bb21b6f31b21837da7898cd3502a40bf43f0605c0d23c60342b2971bf7b91e92be0c366994d174d79dbc063e6b8670fcc4c0886
|
data/abstractivator.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
22
|
spec.add_development_dependency 'rake'
|
23
23
|
spec.add_development_dependency 'eventmachine'
|
24
|
+
spec.add_development_dependency 'mongoid'
|
24
25
|
|
25
26
|
spec.add_runtime_dependency 'activesupport', '~> 4.0'
|
26
27
|
spec.add_runtime_dependency 'sourcify', '> 0'
|
@@ -33,5 +33,15 @@ module Abstractivator
|
|
33
33
|
raise error if error
|
34
34
|
result
|
35
35
|
end
|
36
|
+
|
37
|
+
def mongoid_fiber_defer(&action)
|
38
|
+
db = Mongoid::Threaded.database_override
|
39
|
+
fiber_defer do
|
40
|
+
# in the background thread
|
41
|
+
Mongoid.override_database(db) # set the db to what it was in the main thread
|
42
|
+
action.call
|
43
|
+
end
|
44
|
+
Mongoid.override_database(db) # main thread has moved on before we resume here. restore the db override.
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'abstractivator/fiber_defer'
|
3
3
|
require 'eventmachine'
|
4
|
+
require 'mongoid'
|
4
5
|
|
5
6
|
describe Abstractivator::FiberDefer do
|
6
7
|
include Abstractivator::FiberDefer
|
@@ -71,4 +72,30 @@ describe Abstractivator::FiberDefer do
|
|
71
72
|
end
|
72
73
|
end
|
73
74
|
end
|
75
|
+
|
76
|
+
describe '#mongoid_fiber_defer' do
|
77
|
+
it 'restores the mongoid database override within and after the deferred action' do
|
78
|
+
the_log = []
|
79
|
+
log = proc { the_log << Mongoid::Threaded.database_override }
|
80
|
+
EM.run do
|
81
|
+
with_fiber_defer do
|
82
|
+
Mongoid.override_database('good')
|
83
|
+
mongoid_fiber_defer do
|
84
|
+
sleep(0.1) # let the main thread proceed to set 'bad'
|
85
|
+
log.call # regardless, we should get 'good' here
|
86
|
+
EM.next_tick do
|
87
|
+
Mongoid.override_database('bad') # something else sets 'bad' again on the main thread
|
88
|
+
log.call
|
89
|
+
end
|
90
|
+
sleep(0.1) # allow main thread to run
|
91
|
+
end
|
92
|
+
log.call # back on the main thread now, we should see 'good'
|
93
|
+
EM.stop
|
94
|
+
end
|
95
|
+
Mongoid.override_database('bad') # this runs right after the background thread is started
|
96
|
+
log.call
|
97
|
+
end
|
98
|
+
expect(the_log).to eql %w(bad good bad good)
|
99
|
+
end
|
100
|
+
end
|
74
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abstractivator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Winton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mongoid
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: activesupport
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|