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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 137c22fc6804e7a6d4261c63b139287c06aa44020f315318982d9c301cac6676
4
- data.tar.gz: caaef13d6e976628e0d94d6dc0a5c615c1a50b14e48b1b66f4d2393e179b2548
3
+ metadata.gz: c5772a5edc3139fabf4602d96c59fc69fe3ac83ae016d286a2257deac26ae8e0
4
+ data.tar.gz: e0e6a52da707287733bcc0bb22a4d34e515bec9e2e869f0a2ac4f49696e07b19
5
5
  SHA512:
6
- metadata.gz: af3a795753d0f1dd53964c02355cc37845228316f3c2361fc9cca3270baede2355f63d88b997e43a93df320930072d1a3bac8a4038795aa4b9322aaaef9ad921
7
- data.tar.gz: 42bb95792ed9035a6b4766b4370852ef27b17ceebce9a24d98bc43aac766057ddd67d493a420e2526f0a12e8022f6efe260a21b64e491a6e0a1ef033ec2b538b
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
- self._remote_model = args.first
93
+ @remote_model = args.first
96
94
 
97
- self.__remotable_included ||= begin
98
- require "remotable/active_record_extender"
99
- include Remotable::ActiveRecordExtender
100
- true
101
- end
95
+ ensure_remotable_included!
102
96
 
103
- extend_remote_model(_remote_model) if _remote_model
97
+ extend_remote_model(@remote_model) if @remote_model
104
98
  end
105
- _remote_model
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
- original = self.remote_model
114
- self.remote_model(model)
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.remote_model(original)
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
- threadsafe_attribute :_remote_key, :_expires_after, :_remote_attribute_map,
49
- :_local_attribute_routes, :_remote_timeout, :remotable_skip_validation_on_sync
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
- self._remote_key = remote_key
84
+ @remote_key = remote_key
87
85
  else
88
- _remote_key || generate_default_remote_key
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 _remote_key if _remote_key
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
@@ -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
- threadsafe_attribute :_nosync
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
@@ -1,3 +1,3 @@
1
1
  module Remotable
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
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.5.1
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-14 00:00:00.000000000 Z
11
+ date: 2020-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource