remotable 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/remotable.rb +37 -13
- data/lib/remotable/active_record_extender.rb +5 -7
- data/lib/remotable/nosync.rb +9 -4
- data/lib/remotable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5772a5edc3139fabf4602d96c59fc69fe3ac83ae016d286a2257deac26ae8e0
|
4
|
+
data.tar.gz: e0e6a52da707287733bcc0bb22a4d34e515bec9e2e869f0a2ac4f49696e07b19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec594e5275ecb8a7dbd7df17f5c1addfc16f3b982391d8bb88079dc3922f3d62549ef4422bad8d9c9113d7528077490947d3999ca02d32cc2d12a262acad8980
|
7
|
+
data.tar.gz: 5d4c975e43ab1e62af43e257eacd0d5f28a32729ed31de556ef8bf950890db1bf7117d06c0d669cb9ceb8a189f24e77fafda0dd177ff643a41fef4b2615d6117
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### 0.6.0
|
4
|
+
* **Bugfix** Completely removed dependence on `activeresource`'s `ThreadsafeAttributes`. This makes multithreaded behavior more deterministic and involves fewer edgecases, since things meant to be global state are reverted back to being so, while things meant to have a per-thread scope are constrained as they should be.
|
5
|
+
|
3
6
|
### 0.5.1
|
4
7
|
* **Bugfix** Addressed an issue where `Remotable.with_remote_model` could leave a model with the wrong `remote_model` when used in a multithreaded environment.
|
5
8
|
|
data/lib/remotable.rb
CHANGED
@@ -5,7 +5,6 @@ require "remotable/validate_models"
|
|
5
5
|
require "remotable/with_remote_model_proxy"
|
6
6
|
require "remotable/errors"
|
7
7
|
require "remotable/logger_wrapper"
|
8
|
-
require "active_resource/threadsafe_attributes"
|
9
8
|
|
10
9
|
|
11
10
|
# Remotable keeps a locally-stored ActiveRecord
|
@@ -55,7 +54,6 @@ module Remotable
|
|
55
54
|
Remotable.log_level = :debug
|
56
55
|
end
|
57
56
|
|
58
|
-
threadsafe_attribute :_remote_model, :__remotable_included
|
59
57
|
|
60
58
|
|
61
59
|
|
@@ -92,17 +90,13 @@ module Remotable
|
|
92
90
|
#
|
93
91
|
def remote_model(*args)
|
94
92
|
if args.length >= 1
|
95
|
-
|
93
|
+
@remote_model = args.first
|
96
94
|
|
97
|
-
|
98
|
-
require "remotable/active_record_extender"
|
99
|
-
include Remotable::ActiveRecordExtender
|
100
|
-
true
|
101
|
-
end
|
95
|
+
ensure_remotable_included!
|
102
96
|
|
103
|
-
extend_remote_model(
|
97
|
+
extend_remote_model(@remote_model) if @remote_model
|
104
98
|
end
|
105
|
-
|
99
|
+
override_remote_model? ? _remote_model_override : @remote_model
|
106
100
|
end
|
107
101
|
|
108
102
|
|
@@ -110,11 +104,13 @@ module Remotable
|
|
110
104
|
def with_remote_model(model)
|
111
105
|
if block_given?
|
112
106
|
begin
|
113
|
-
|
114
|
-
|
107
|
+
extend_remote_model(model) if model
|
108
|
+
ensure_remotable_included!
|
109
|
+
self._remote_model_override = model
|
110
|
+
self._use_remote_model_override = true
|
115
111
|
yield
|
116
112
|
ensure
|
117
|
-
self.
|
113
|
+
self._use_remote_model_override = false
|
118
114
|
end
|
119
115
|
else
|
120
116
|
WithRemoteModelProxy.new(self, model)
|
@@ -151,6 +147,34 @@ module Remotable
|
|
151
147
|
|
152
148
|
private
|
153
149
|
|
150
|
+
def override_remote_model?
|
151
|
+
!!_use_remote_model_override
|
152
|
+
end
|
153
|
+
|
154
|
+
def ensure_remotable_included!
|
155
|
+
@__remotable_included ||= begin
|
156
|
+
require "remotable/active_record_extender"
|
157
|
+
include Remotable::ActiveRecordExtender
|
158
|
+
true
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def _remote_model_override
|
163
|
+
Thread.current.thread_variable_get "remotable._remote_model_override.#{self.object_id}"
|
164
|
+
end
|
165
|
+
|
166
|
+
def _remote_model_override=(value)
|
167
|
+
Thread.current.thread_variable_set "remotable._remote_model_override.#{self.object_id}", value
|
168
|
+
end
|
169
|
+
|
170
|
+
def _use_remote_model_override
|
171
|
+
Thread.current.thread_variable_get "remotable._use_remote_model_override.#{self.object_id}"
|
172
|
+
end
|
173
|
+
|
174
|
+
def _use_remote_model_override=(value)
|
175
|
+
Thread.current.thread_variable_set "remotable._use_remote_model_override.#{self.object_id}", value
|
176
|
+
end
|
177
|
+
|
154
178
|
def extend_remote_model(remote_model)
|
155
179
|
if remote_model.is_a?(Class) and (remote_model < ActiveResource::Base)
|
156
180
|
require "remotable/adapters/active_resource"
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require "remotable/core_ext"
|
2
2
|
require "active_support/concern"
|
3
3
|
require "active_support/core_ext/array/wrap"
|
4
|
-
require "active_resource/threadsafe_attributes"
|
5
4
|
require "benchmark"
|
6
5
|
|
7
6
|
|
@@ -43,10 +42,9 @@ module Remotable
|
|
43
42
|
|
44
43
|
module ClassMethods
|
45
44
|
include Nosync
|
46
|
-
include ThreadsafeAttributes
|
47
45
|
|
48
|
-
|
49
|
-
:
|
46
|
+
attr_accessor :_remote_attribute_map, :_local_attribute_routes, :_expires_after,
|
47
|
+
:_remote_timeout, :remotable_skip_validation_on_sync
|
50
48
|
|
51
49
|
def nosync?
|
52
50
|
return true if remote_model.nil?
|
@@ -83,9 +81,9 @@ module Remotable
|
|
83
81
|
# Set up a finder method for the remote_key
|
84
82
|
fetch_with(local_key(remote_key), options)
|
85
83
|
|
86
|
-
|
84
|
+
@remote_key = remote_key
|
87
85
|
else
|
88
|
-
|
86
|
+
@remote_key || generate_default_remote_key
|
89
87
|
end
|
90
88
|
end
|
91
89
|
|
@@ -431,7 +429,7 @@ module Remotable
|
|
431
429
|
|
432
430
|
|
433
431
|
def generate_default_remote_key
|
434
|
-
return
|
432
|
+
return @remote_key if @remote_key
|
435
433
|
raise("No remote key supplied and :id is not a remote attribute") unless remote_attribute_names.member?(:id)
|
436
434
|
remote_key(:id)
|
437
435
|
end
|
data/lib/remotable/nosync.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "active_resource/threadsafe_attributes"
|
2
|
-
|
3
1
|
module Remotable
|
4
2
|
module Nosync
|
5
3
|
|
@@ -50,7 +48,6 @@ module Remotable
|
|
50
48
|
end
|
51
49
|
|
52
50
|
module ClassMethods
|
53
|
-
include ThreadsafeAttributes
|
54
51
|
include InstanceMethods
|
55
52
|
|
56
53
|
def reset_nosync!
|
@@ -62,7 +59,15 @@ module Remotable
|
|
62
59
|
end
|
63
60
|
|
64
61
|
private
|
65
|
-
|
62
|
+
|
63
|
+
def _nosync
|
64
|
+
Thread.current.thread_variable_get "remotable.nosync.#{self.object_id}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def _nosync=(value)
|
68
|
+
Thread.current.thread_variable_set "remotable.nosync.#{self.object_id}", value
|
69
|
+
end
|
70
|
+
|
66
71
|
end
|
67
72
|
|
68
73
|
end
|
data/lib/remotable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remotable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|