rails_multitenant 0.17.0 → 0.18.1

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: f12466f03396bc81cc80442aa94dbcc15300b8c6b6455ab10b44fb119d5b0c4a
4
- data.tar.gz: 8c0f7cf5d1194a6b203c6f95779ad5deafe030d982d33d812fdf2df89cc6d582
3
+ metadata.gz: 3336c472e8e9f781be0c82a83859dd33c9566a4753c590a8527804974384a5ce
4
+ data.tar.gz: 9963126e661148092ec99d18a431b6049ddbb2cc8448bd10503bea2765567750
5
5
  SHA512:
6
- metadata.gz: 045d489fe1f2b98ac9491434600b0551c695af632753cc27906f172fcf6170c22370dfabca3637041492762a725317d82b59ac90aa050f7c70ad5b71948dfc57
7
- data.tar.gz: '075395d1f3d9944640cbc0b3ae4ce01da72ec237f3814233418b4022abf07ed8921591b306cbb5b5c638778683e420da28166835d641d390b7274e2673616bf0'
6
+ metadata.gz: 443db952a9e4b0d8769eac2a58d7b004fba3391fdc08ff1883a5a05c37a43fbebc1237c78c16c104aad8da67c896e9ac253073a8627b9c13a129d092d0d21995
7
+ data.tar.gz: ee3d3bbb473467c6d49a8c7b388a1e6eb236a4b5cad84753a88eecb0786896039478b91a68b2cba07deb04eaefa3848464bf4385d36fa996271ce2c50d27a9bd
@@ -34,8 +34,9 @@ module RailsMultitenant
34
34
  current || raise("No current #{name} set")
35
35
  end
36
36
 
37
- def clear_current!
37
+ def clear_current!(cleared = nil)
38
38
  GlobalContextRegistry.delete(current_registry_obj)
39
+ __clear_dependents!(cleared)
39
40
  end
40
41
 
41
42
  def as_current(object)
@@ -73,8 +74,13 @@ module RailsMultitenant
73
74
  end
74
75
  end
75
76
 
76
- def __clear_dependents!
77
- GlobalContextRegistry.send(:dependencies_for, __key_class).each(&:clear_current!)
77
+ def __clear_dependents!(initial_cleared = nil)
78
+ GlobalContextRegistry.send(:dependencies_for, __key_class).tap do |dependencies|
79
+ next unless dependencies.present?
80
+
81
+ (cleared = initial_cleared || []) << self
82
+ dependencies.each { |obj| obj.clear_current!(cleared) unless cleared.include?(obj) }
83
+ end
78
84
  end
79
85
 
80
86
  def __key_class
@@ -60,15 +60,22 @@ module RailsMultitenant
60
60
  self.current = old_model
61
61
  end
62
62
 
63
- def clear_current!
63
+ def clear_current!(cleared = nil)
64
64
  GlobalContextRegistry.delete(current_instance_registry_obj)
65
+ __clear_dependents!(cleared)
65
66
  end
66
67
 
67
68
  private
68
69
 
69
- def __clear_dependents!
70
+ def __clear_dependents!(initial_cleared = nil)
70
71
  key_class = respond_to?(:base_class) ? base_class : self
71
- GlobalContextRegistry.send(:dependencies_for, key_class).each(&:clear_current!)
72
+
73
+ GlobalContextRegistry.send(:dependencies_for, key_class).tap do |dependencies|
74
+ next unless dependencies.present?
75
+
76
+ (cleared = initial_cleared || []) << self
77
+ dependencies.each { |obj| obj.clear_current!(cleared) unless cleared.include?(obj) }
78
+ end
72
79
  end
73
80
 
74
81
  def current_instance_registry_id
@@ -8,6 +8,12 @@ module RailsMultitenant
8
8
  def global_context_dependent_on(*klasses)
9
9
  klasses.each { |klass| GlobalContextRegistry.send(:add_dependency, klass, self) }
10
10
  end
11
+
12
+ # Registers a bi-directional dependency on another class.
13
+ def global_context_mutually_dependent_on(*klasses)
14
+ global_context_dependent_on(*klasses)
15
+ klasses.each { |klass| klass.global_context_dependent_on(self) }
16
+ end
11
17
  end
12
18
  end
13
19
  end
@@ -14,6 +14,8 @@ module RailsMultitenant
14
14
  module GlobalContextRegistry
15
15
  extend self
16
16
 
17
+ EMPTY_ARRAY = [].freeze
18
+
17
19
  # Set this global
18
20
  def set(symbol, value)
19
21
  globals[symbol] = value
@@ -114,11 +116,16 @@ module RailsMultitenant
114
116
  @dependencies = {}
115
117
 
116
118
  def add_dependency(parent, dependent)
117
- (@dependencies[parent] ||= []) << dependent
119
+ parent = parent.respond_to?(:name) ? parent.name : parent
120
+ dependent = dependent.respond_to?(:name) ? dependent.name : dependent
121
+
122
+ raise 'dependencies cannot be registered for anonymous classes' if parent.blank? || dependent.blank?
123
+
124
+ ((@dependencies[parent] ||= []) << dependent).tap(&:uniq!)
118
125
  end
119
126
 
120
127
  def dependencies_for(klass)
121
- @dependencies[klass] || []
128
+ @dependencies[klass.name]&.map(&:safe_constantize)&.tap(&:compact!) || EMPTY_ARRAY
122
129
  end
123
130
 
124
131
  def globals
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsMultitenant
4
- VERSION = '0.17.0'
4
+ VERSION = '0.18.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_multitenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Breault
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-09 00:00:00.000000000 Z
11
+ date: 2023-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -168,14 +168,14 @@ dependencies:
168
168
  requirements:
169
169
  - - "~>"
170
170
  - !ruby/object:Gem::Version
171
- version: 1.4.0
171
+ version: 1.6.0
172
172
  type: :development
173
173
  prerelease: false
174
174
  version_requirements: !ruby/object:Gem::Requirement
175
175
  requirements:
176
176
  - - "~>"
177
177
  - !ruby/object:Gem::Version
178
- version: 1.4.0
178
+ version: 1.6.0
179
179
  description: Handles multiple tenants in a Rails environment
180
180
  email:
181
181
  - pbreault@salsify.com
@@ -216,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
216
  - !ruby/object:Gem::Version
217
217
  version: '0'
218
218
  requirements: []
219
- rubygems_version: 3.3.7
219
+ rubygems_version: 3.3.26
220
220
  signing_key:
221
221
  specification_version: 4
222
222
  summary: Automatically configures multiple tenants in a Rails environment