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.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.txt +21 -0
  3. data/lib/rails_multitenant.rb +7 -4
  4. data/lib/rails_multitenant/global_context_registry.rb +43 -198
  5. data/lib/rails_multitenant/global_context_registry/current.rb +98 -0
  6. data/lib/rails_multitenant/global_context_registry/current_instance.rb +103 -0
  7. data/lib/rails_multitenant/global_context_registry/registry_dependent_on.rb +13 -0
  8. data/lib/rails_multitenant/middleware/extensions.rb +3 -3
  9. data/lib/rails_multitenant/middleware/isolated_context_registry.rb +2 -0
  10. data/lib/rails_multitenant/middleware/railtie.rb +3 -1
  11. data/lib/rails_multitenant/multitenant_model.rb +6 -2
  12. data/lib/rails_multitenant/rspec.rb +2 -0
  13. data/lib/rails_multitenant/version.rb +3 -1
  14. metadata +69 -76
  15. data/.gitignore +0 -14
  16. data/.rspec +0 -3
  17. data/.ruby-version +0 -1
  18. data/.travis.yml +0 -29
  19. data/CHANGELOG.md +0 -57
  20. data/CODE_OF_CONDUCT.md +0 -13
  21. data/Gemfile +0 -4
  22. data/README.md +0 -120
  23. data/Rakefile +0 -8
  24. data/bin/console +0 -14
  25. data/bin/setup +0 -7
  26. data/rails_multitenant.gemspec +0 -33
  27. data/spec/be_multitenant_on_matcher_spec.rb +0 -15
  28. data/spec/current_spec.rb +0 -118
  29. data/spec/db/database.yml +0 -3
  30. data/spec/db/schema.rb +0 -60
  31. data/spec/external_item_spec.rb +0 -36
  32. data/spec/external_item_with_optional_org_spec.rb +0 -25
  33. data/spec/global_context_registry_spec.rb +0 -113
  34. data/spec/item_spec.rb +0 -78
  35. data/spec/item_subtype_spec.rb +0 -37
  36. data/spec/item_with_optional_org_spec.rb +0 -26
  37. data/spec/middleware_isolated_context_registry_spec.rb +0 -15
  38. data/spec/rails_multitenant_spec.rb +0 -51
  39. 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,5 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_multitenant/middleware/isolated_context_registry'
2
4
 
3
- if defined?(Rails)
4
- require 'rails_multitenant/middleware/railtie'
5
- end
5
+ require 'rails_multitenant/middleware/railtie' if defined?(Rails)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsMultitenant
2
4
  module Middleware
3
5
  class IsolatedContextRegistry
@@ -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 "rails_multitenant.middleware" do |app|
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
- where(context_entity_id_field => GlobalContextRegistry[context_entity_id_field])
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 | [ context_entity_id_field ]
49
+ scope = existing_scope | [context_entity_id_field]
46
50
  validates_uniqueness_of(*attr_names, options.merge(scope: scope))
47
51
  end
48
52
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec::Matchers.define(:be_multitenant_on) do |expected|
2
4
  match do |actual|
3
5
  actual.respond_to?(:context_entity_id_field) && actual.context_entity_id_field == expected
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsMultitenant
2
- VERSION = '0.11.0'
4
+ VERSION = '0.15.0'
3
5
  end
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.11.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: 2019-02-25 00:00:00.000000000 Z
11
+ date: 2020-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
20
- type: :development
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: '1.10'
29
+ version: '4.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.2'
27
33
  - !ruby/object:Gem::Dependency
28
- name: activerecord
34
+ name: activesupport
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: '4.1'
39
+ version: '4.2'
34
40
  - - "<"
35
41
  - !ruby/object:Gem::Version
36
- version: '5.3'
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.1'
49
+ version: '4.2'
44
50
  - - "<"
45
51
  - !ruby/object:Gem::Version
46
- version: '5.3'
52
+ version: '6.2'
47
53
  - !ruby/object:Gem::Dependency
48
- name: activesupport
54
+ name: appraisal
49
55
  requirement: !ruby/object:Gem::Requirement
50
56
  requirements:
51
57
  - - ">="
52
58
  - !ruby/object:Gem::Version
53
- version: '4.1'
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: '4.1'
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: '11.0'
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: '11.0'
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: '2'
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: '2'
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.3.0
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.3.0
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
- - ".gitignore"
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.1.0
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
- rubyforge_project:
211
- rubygems_version: 2.6.14
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
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /log/
11
-
12
- bundle
13
- .idea
14
- *.iml
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --format documentation
3
- --require spec_helper
@@ -1 +0,0 @@
1
- 2.4.3
@@ -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'
@@ -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`.