rails_multitenant 0.11.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE.txt +21 -0
- data/lib/rails_multitenant.rb +7 -4
- data/lib/rails_multitenant/global_context_registry.rb +43 -198
- data/lib/rails_multitenant/global_context_registry/current.rb +98 -0
- data/lib/rails_multitenant/global_context_registry/current_instance.rb +103 -0
- data/lib/rails_multitenant/global_context_registry/registry_dependent_on.rb +13 -0
- data/lib/rails_multitenant/middleware/extensions.rb +3 -3
- data/lib/rails_multitenant/middleware/isolated_context_registry.rb +2 -0
- data/lib/rails_multitenant/middleware/railtie.rb +3 -1
- data/lib/rails_multitenant/multitenant_model.rb +6 -2
- data/lib/rails_multitenant/rspec.rb +2 -0
- data/lib/rails_multitenant/version.rb +3 -1
- metadata +69 -76
- data/.gitignore +0 -14
- data/.rspec +0 -3
- data/.ruby-version +0 -1
- data/.travis.yml +0 -29
- data/CHANGELOG.md +0 -57
- data/CODE_OF_CONDUCT.md +0 -13
- data/Gemfile +0 -4
- data/README.md +0 -120
- data/Rakefile +0 -8
- data/bin/console +0 -14
- data/bin/setup +0 -7
- data/rails_multitenant.gemspec +0 -33
- data/spec/be_multitenant_on_matcher_spec.rb +0 -15
- data/spec/current_spec.rb +0 -118
- data/spec/db/database.yml +0 -3
- data/spec/db/schema.rb +0 -60
- data/spec/external_item_spec.rb +0 -36
- data/spec/external_item_with_optional_org_spec.rb +0 -25
- data/spec/global_context_registry_spec.rb +0 -113
- data/spec/item_spec.rb +0 -78
- data/spec/item_subtype_spec.rb +0 -37
- data/spec/item_with_optional_org_spec.rb +0 -26
- data/spec/middleware_isolated_context_registry_spec.rb +0 -15
- data/spec/rails_multitenant_spec.rb +0 -51
- data/spec/spec_helper.rb +0 -54
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsMultitenant
|
4
|
+
module GlobalContextRegistry
|
5
|
+
module RegistryDependentOn
|
6
|
+
# Is this class dependent on changes in another GlobalContextRegistry-
|
7
|
+
# stored object? Register that dependency here.
|
8
|
+
def global_context_dependent_on(*klasses)
|
9
|
+
klasses.each { |klass| GlobalContextRegistry.send(:add_dependency, klass, self) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RailsMultitenant
|
2
4
|
module Middleware
|
3
5
|
class Railtie < ::Rails::Railtie
|
4
|
-
initializer
|
6
|
+
initializer 'rails_multitenant.middleware' do |app|
|
5
7
|
app.config.middleware.insert 0, ::RailsMultitenant::Middleware::IsolatedContextRegistry
|
6
8
|
end
|
7
9
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RailsMultitenant
|
2
4
|
module MultitenantModel
|
3
5
|
extend ActiveSupport::Concern
|
@@ -16,7 +18,9 @@ module RailsMultitenant
|
|
16
18
|
scope_sym = "from_current_#{context_entity}".to_sym
|
17
19
|
|
18
20
|
scope scope_sym, -> do
|
19
|
-
|
21
|
+
unless GlobalContextRegistry.use_unscoped_queries?
|
22
|
+
where(context_entity_id_field => GlobalContextRegistry[context_entity_id_field])
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
default_scope { send(scope_sym) }
|
@@ -42,7 +46,7 @@ module RailsMultitenant
|
|
42
46
|
def validates_multitenant_uniqueness_of(*attr_names)
|
43
47
|
options = attr_names.extract_options!.symbolize_keys
|
44
48
|
existing_scope = Array.wrap(options.delete(:scope))
|
45
|
-
scope = existing_scope | [
|
49
|
+
scope = existing_scope | [context_entity_id_field]
|
46
50
|
validates_uniqueness_of(*attr_names, options.merge(scope: scope))
|
47
51
|
end
|
48
52
|
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_multitenant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Breault
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
|
19
|
+
version: '4.2'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.2'
|
23
|
+
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
29
|
+
version: '4.2'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.2'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
34
|
+
name: activesupport
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '4.
|
39
|
+
version: '4.2'
|
34
40
|
- - "<"
|
35
41
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
42
|
+
version: '6.2'
|
37
43
|
type: :runtime
|
38
44
|
prerelease: false
|
39
45
|
version_requirements: !ruby/object:Gem::Requirement
|
40
46
|
requirements:
|
41
47
|
- - ">="
|
42
48
|
- !ruby/object:Gem::Version
|
43
|
-
version: '4.
|
49
|
+
version: '4.2'
|
44
50
|
- - "<"
|
45
51
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
52
|
+
version: '6.2'
|
47
53
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
54
|
+
name: appraisal
|
49
55
|
requirement: !ruby/object:Gem::Requirement
|
50
56
|
requirements:
|
51
57
|
- - ">="
|
52
58
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
54
|
-
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '5.3'
|
57
|
-
type: :runtime
|
59
|
+
version: '0'
|
60
|
+
type: :development
|
58
61
|
prerelease: false
|
59
62
|
version_requirements: !ruby/object:Gem::Requirement
|
60
63
|
requirements:
|
61
64
|
- - ">="
|
62
65
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
64
|
-
- - "<"
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '5.3'
|
66
|
+
version: '0'
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: coveralls
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,30 +96,58 @@ dependencies:
|
|
96
96
|
name: rake
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
|
-
- - "
|
99
|
+
- - ">="
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version: '
|
101
|
+
version: '12.0'
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
|
-
- - "
|
106
|
+
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
|
-
version: '
|
108
|
+
version: '12.0'
|
109
109
|
- !ruby/object:Gem::Dependency
|
110
110
|
name: rspec
|
111
111
|
requirement: !ruby/object:Gem::Requirement
|
112
112
|
requirements:
|
113
113
|
- - "~>"
|
114
114
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
115
|
+
version: 3.8.0
|
116
116
|
type: :development
|
117
117
|
prerelease: false
|
118
118
|
version_requirements: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
120
|
- - "~>"
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version:
|
122
|
+
version: 3.8.0
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: rspec_junit_formatter
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: salsify_rubocop
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - '='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: 0.63.0
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - '='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 0.63.0
|
123
151
|
- !ruby/object:Gem::Dependency
|
124
152
|
name: simplecov
|
125
153
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,14 +168,14 @@ dependencies:
|
|
140
168
|
requirements:
|
141
169
|
- - "~>"
|
142
170
|
- !ruby/object:Gem::Version
|
143
|
-
version: 1.
|
171
|
+
version: 1.4.0
|
144
172
|
type: :development
|
145
173
|
prerelease: false
|
146
174
|
version_requirements: !ruby/object:Gem::Requirement
|
147
175
|
requirements:
|
148
176
|
- - "~>"
|
149
177
|
- !ruby/object:Gem::Version
|
150
|
-
version: 1.
|
178
|
+
version: 1.4.0
|
151
179
|
description: Handles multiple tenants in a Rails environment
|
152
180
|
email:
|
153
181
|
- pbreault@salsify.com
|
@@ -155,44 +183,23 @@ executables: []
|
|
155
183
|
extensions: []
|
156
184
|
extra_rdoc_files: []
|
157
185
|
files:
|
158
|
-
-
|
159
|
-
- ".rspec"
|
160
|
-
- ".ruby-version"
|
161
|
-
- ".travis.yml"
|
162
|
-
- CHANGELOG.md
|
163
|
-
- CODE_OF_CONDUCT.md
|
164
|
-
- Gemfile
|
165
|
-
- README.md
|
166
|
-
- Rakefile
|
167
|
-
- bin/console
|
168
|
-
- bin/setup
|
186
|
+
- LICENSE.txt
|
169
187
|
- lib/rails_multitenant.rb
|
170
188
|
- lib/rails_multitenant/global_context_registry.rb
|
189
|
+
- lib/rails_multitenant/global_context_registry/current.rb
|
190
|
+
- lib/rails_multitenant/global_context_registry/current_instance.rb
|
191
|
+
- lib/rails_multitenant/global_context_registry/registry_dependent_on.rb
|
171
192
|
- lib/rails_multitenant/middleware/extensions.rb
|
172
193
|
- lib/rails_multitenant/middleware/isolated_context_registry.rb
|
173
194
|
- lib/rails_multitenant/middleware/railtie.rb
|
174
195
|
- lib/rails_multitenant/multitenant_model.rb
|
175
196
|
- lib/rails_multitenant/rspec.rb
|
176
197
|
- lib/rails_multitenant/version.rb
|
177
|
-
- rails_multitenant.gemspec
|
178
|
-
- spec/be_multitenant_on_matcher_spec.rb
|
179
|
-
- spec/current_spec.rb
|
180
|
-
- spec/db/database.yml
|
181
|
-
- spec/db/schema.rb
|
182
|
-
- spec/external_item_spec.rb
|
183
|
-
- spec/external_item_with_optional_org_spec.rb
|
184
|
-
- spec/global_context_registry_spec.rb
|
185
|
-
- spec/item_spec.rb
|
186
|
-
- spec/item_subtype_spec.rb
|
187
|
-
- spec/item_with_optional_org_spec.rb
|
188
|
-
- spec/middleware_isolated_context_registry_spec.rb
|
189
|
-
- spec/rails_multitenant_spec.rb
|
190
|
-
- spec/spec_helper.rb
|
191
198
|
homepage: https://github.com/salsify/rails-multitenant
|
192
199
|
licenses:
|
193
200
|
- MIT
|
194
201
|
metadata: {}
|
195
|
-
post_install_message:
|
202
|
+
post_install_message:
|
196
203
|
rdoc_options: []
|
197
204
|
require_paths:
|
198
205
|
- lib
|
@@ -200,29 +207,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
207
|
requirements:
|
201
208
|
- - ">="
|
202
209
|
- !ruby/object:Gem::Version
|
203
|
-
version: 2.
|
210
|
+
version: 2.4.0
|
204
211
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
212
|
requirements:
|
206
213
|
- - ">="
|
207
214
|
- !ruby/object:Gem::Version
|
208
215
|
version: '0'
|
209
216
|
requirements: []
|
210
|
-
|
211
|
-
|
212
|
-
signing_key:
|
217
|
+
rubygems_version: 3.0.4
|
218
|
+
signing_key:
|
213
219
|
specification_version: 4
|
214
220
|
summary: Automatically configures multiple tenants in a Rails environment
|
215
|
-
test_files:
|
216
|
-
- spec/spec_helper.rb
|
217
|
-
- spec/global_context_registry_spec.rb
|
218
|
-
- spec/external_item_spec.rb
|
219
|
-
- spec/item_subtype_spec.rb
|
220
|
-
- spec/current_spec.rb
|
221
|
-
- spec/item_spec.rb
|
222
|
-
- spec/external_item_with_optional_org_spec.rb
|
223
|
-
- spec/db/schema.rb
|
224
|
-
- spec/db/database.yml
|
225
|
-
- spec/be_multitenant_on_matcher_spec.rb
|
226
|
-
- spec/rails_multitenant_spec.rb
|
227
|
-
- spec/item_with_optional_org_spec.rb
|
228
|
-
- spec/middleware_isolated_context_registry_spec.rb
|
221
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.4.3
|
data/.travis.yml
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
sudo: false
|
3
|
-
env:
|
4
|
-
- RAILS_VERSION="~> 4.1.16"
|
5
|
-
- RAILS_VERSION="~> 4.2.10"
|
6
|
-
- RAILS_VERSION="~> 5.0.7"
|
7
|
-
- RAILS_VERSION="~> 5.1.6"
|
8
|
-
- RAILS_VERSION="~> 5.2.0"
|
9
|
-
rvm:
|
10
|
-
- 2.5.1
|
11
|
-
- 2.4.4
|
12
|
-
- 2.3.7
|
13
|
-
- 2.2.10
|
14
|
-
- 2.1.10
|
15
|
-
matrix:
|
16
|
-
exclude:
|
17
|
-
- rvm: 2.1.10
|
18
|
-
env: RAILS_VERSION="~> 5.0.7"
|
19
|
-
- rvm: 2.1.10
|
20
|
-
env: RAILS_VERSION="~> 5.1.6"
|
21
|
-
- rvm: 2.1.10
|
22
|
-
env: RAILS_VERSION="~> 5.2.0"
|
23
|
-
- rvm: 2.4.4
|
24
|
-
env: RAILS_VERSION="~> 4.1.16"
|
25
|
-
- rvm: 2.5.1
|
26
|
-
env: RAILS_VERSION="~> 4.1.16"
|
27
|
-
before_install:
|
28
|
-
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
29
|
-
- gem install bundler -v '< 2'
|
data/CHANGELOG.md
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# Changelog
|
2
|
-
|
3
|
-
### 0.11.0
|
4
|
-
* Provide shorthands to access `RailsMultitenant::GlobalContextRegistry` methods via `RailsMultitenant`.
|
5
|
-
For example `RailsMultitenant[:organization_id] = 'some value'` will set that value in the registry.
|
6
|
-
|
7
|
-
### 0.10.0
|
8
|
-
* Rails 5.2 support.
|
9
|
-
|
10
|
-
### 0.9.0
|
11
|
-
* Modify `Current.current` to return a specified default, when not already initialized, or `nil`
|
12
|
-
when no default is specified.
|
13
|
-
* Add `Current.provide_default` to optionally specify a default value for `Current.current`.
|
14
|
-
* Add `Current.current=` / `Current.current?` / `Current.current!` / `Current.as_current`.
|
15
|
-
|
16
|
-
### 0.8.0
|
17
|
-
* Switch usage of Fixnum to Integer for Ruby > 2.4
|
18
|
-
* Test with multiple Rubies
|
19
|
-
|
20
|
-
### 0.7.2
|
21
|
-
* Fix bug that prevents clearing dependents of classes derived from CurrentInstance.
|
22
|
-
|
23
|
-
### 0.7.1
|
24
|
-
* Added as_current multi-tenant class method.
|
25
|
-
|
26
|
-
### 0.7.0
|
27
|
-
* Add Rack middleware to create a new isolated registry per request.
|
28
|
-
|
29
|
-
### 0.6.0
|
30
|
-
* Rails 5.1 support.
|
31
|
-
|
32
|
-
### 0.5.2
|
33
|
-
* Optimize `CurrentInstance.current` / `CurrentInstance.current_id` / `CurrentInstance.current=`
|
34
|
-
/ `CurrentInstance.current_id=`.
|
35
|
-
|
36
|
-
### 0.5.1
|
37
|
-
* Fix incorrect Rails version dependency in rubygems.org.
|
38
|
-
|
39
|
-
### 0.5.0
|
40
|
-
* Add `required` option to `multitenant_on` and `multitenant_on_model`.
|
41
|
-
|
42
|
-
### 0.4.0
|
43
|
-
* Fix be_multitenant_on matcher to handle models that don't include the `RailsMultitenant::MultitenantModel` module.
|
44
|
-
* Fix `context_entity_id_field` to work with inheritance.
|
45
|
-
* Drop Rails 3.2 and 4.0 support since `unscope` doesn't work propertly with default scopes.
|
46
|
-
|
47
|
-
### 0.3.1
|
48
|
-
* Fix strip_<entity>_scope
|
49
|
-
|
50
|
-
### 0.3.0
|
51
|
-
* Modify `RailsMultitenant::GlobalContextRegistry#new_registry` to accept an arg
|
52
|
-
specifying the new registry to set. The previous registry is still returned.
|
53
|
-
|
54
|
-
### 0.2.0
|
55
|
-
* Merged [PR 2](https://github.com/salsify/rails-multitenant/pull/2) which adds support for
|
56
|
-
multi-tenancy based on a foreign key to an external model. As part of this the `multitenant_model_on`
|
57
|
-
method was renamed to `multitenant_on_model`.
|