rails_multitenant 0.12.0 → 0.13.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +21 -0
  3. data/lib/rails_multitenant.rb +7 -4
  4. data/lib/rails_multitenant/global_context_registry.rb +22 -5
  5. data/lib/rails_multitenant/middleware/extensions.rb +3 -3
  6. data/lib/rails_multitenant/middleware/isolated_context_registry.rb +2 -0
  7. data/lib/rails_multitenant/middleware/railtie.rb +3 -1
  8. data/lib/rails_multitenant/multitenant_model.rb +3 -1
  9. data/lib/rails_multitenant/rspec.rb +2 -0
  10. data/lib/rails_multitenant/version.rb +3 -1
  11. metadata +20 -49
  12. data/.gitignore +0 -16
  13. data/.rspec +0 -3
  14. data/.ruby-version +0 -1
  15. data/.travis.yml +0 -16
  16. data/Appraisals +0 -28
  17. data/CHANGELOG.md +0 -61
  18. data/CODE_OF_CONDUCT.md +0 -13
  19. data/Gemfile +0 -4
  20. data/README.md +0 -120
  21. data/Rakefile +0 -8
  22. data/bin/console +0 -14
  23. data/bin/setup +0 -7
  24. data/gemfiles/rails_4.2.gemfile +0 -9
  25. data/gemfiles/rails_5.0.gemfile +0 -9
  26. data/gemfiles/rails_5.1.gemfile +0 -8
  27. data/gemfiles/rails_5.2.gemfile +0 -8
  28. data/gemfiles/rails_6.0.gemfile +0 -8
  29. data/rails_multitenant.gemspec +0 -32
  30. data/spec/be_multitenant_on_matcher_spec.rb +0 -15
  31. data/spec/current_spec.rb +0 -118
  32. data/spec/db/database.yml +0 -3
  33. data/spec/db/schema.rb +0 -60
  34. data/spec/external_item_spec.rb +0 -36
  35. data/spec/external_item_with_optional_org_spec.rb +0 -25
  36. data/spec/global_context_registry_spec.rb +0 -113
  37. data/spec/item_spec.rb +0 -78
  38. data/spec/item_subtype_spec.rb +0 -37
  39. data/spec/item_with_optional_org_spec.rb +0 -26
  40. data/spec/middleware_isolated_context_registry_spec.rb +0 -15
  41. data/spec/rails_multitenant_spec.rb +0 -51
  42. data/spec/spec_helper.rb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59ff37a41d189f0a862756fad37fcde1f1795aa7636c1ff74272b0bfc2a9c0b2
4
- data.tar.gz: aabfc280d54676a28e97377ac3c2efb05d2bbc465cdf5324f1ddf4698254d3e6
3
+ metadata.gz: '076093fe7d37b29994df42aac4d14d7d6343da6cb8933eb5eccad10c46296ead'
4
+ data.tar.gz: c74e198268ecd3b19776d5f7fcb6245b7699e7cc0c94e7875e1adf0314dd0397
5
5
  SHA512:
6
- metadata.gz: ba686f109c703650b17d446119b8aea52c7a9d4c40121e90788b9755219b37b45cedb8abca64f61961233cc06cf152d2f8c1c51ce3c418f9e24dacd535944e84
7
- data.tar.gz: e627d7ed403a1e7c54e224d094d9211a224c2bf598ee20a8465029f4d4ce55962169f506ad053ba1d282dda5b1d283f73128e7833b280a8daa93869237109339
6
+ metadata.gz: c932812c863c1393500aa185b6f09ecce088db356c07612c09cf49a1b1f1e49cff176e1d4b6a5b21b92a5656e5463393a19d64a40ed88f378d3d156e6b2d7aaf
7
+ data.tar.gz: ff326a18fad4f155016929a2834912ce51f43d15c043c183cef1a4ef71196954681228a4b50c9428a7603e440f6203cc97e5137f28976225fa96afb623518088
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Salsify, Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -1,15 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/all'
2
4
  require 'active_record'
3
5
 
4
- require "rails_multitenant/global_context_registry"
5
- require "rails_multitenant/multitenant_model"
6
+ require 'rails_multitenant/global_context_registry'
7
+ require 'rails_multitenant/multitenant_model'
6
8
 
7
- require "rails_multitenant/middleware/extensions"
9
+ require 'rails_multitenant/middleware/extensions'
8
10
 
9
11
  module RailsMultitenant
10
12
  extend self
11
13
 
12
- delegate :get, :[], :fetch, :set, :[]=, :delete, :with_isolated_registry, to: :GlobalContextRegistry
14
+ delegate :get, :[], :fetch, :set, :[]=, :delete, :with_isolated_registry, :merge!, :with_merged_registry,
15
+ to: :GlobalContextRegistry
13
16
  end
14
17
 
15
18
  # rails_multitenant/rspec has to be explicitly included by clients who want to use it
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Handles storing of global state that may be swapped out or unset at
2
4
  # various points. We use this in dandelion to store the current user,
3
5
  # org, catalog, etc.
@@ -35,6 +37,7 @@ module RailsMultitenant
35
37
 
36
38
  def current=(object)
37
39
  raise "#{object} is not a #{self}" if object.present? && !object.is_a?(self)
40
+
38
41
  GlobalContextRegistry.set(current_registry_obj, object)
39
42
  __clear_dependents!
40
43
  end
@@ -78,9 +81,10 @@ module RailsMultitenant
78
81
  end
79
82
 
80
83
  def __current_default
81
- if self.default_provider
82
- default = self.default_provider.call(self)
84
+ if default_provider
85
+ default = default_provider.call(self)
83
86
  raise "#{default} is not a #{self}" if default.present? && !default.is_a?(self)
87
+
84
88
  default
85
89
  end
86
90
  end
@@ -103,7 +107,7 @@ module RailsMultitenant
103
107
  end
104
108
 
105
109
  def current?
106
- self.class.current? && self.equal?(self.class.current)
110
+ self.class.current? && equal?(self.class.current)
107
111
  end
108
112
 
109
113
  end
@@ -124,6 +128,7 @@ module RailsMultitenant
124
128
 
125
129
  def current=(object)
126
130
  raise "#{object} is not a #{self}" if object.present? && !object.is_a?(self)
131
+
127
132
  GlobalContextRegistry.set(current_instance_registry_obj, object)
128
133
  GlobalContextRegistry.set(current_instance_registry_id, object.try(:id))
129
134
  __clear_dependents!
@@ -231,10 +236,15 @@ module RailsMultitenant
231
236
  end
232
237
  alias_method :[], :get
233
238
 
239
+ # merge the given values into the registry
240
+ def merge!(values)
241
+ globals.merge!(values)
242
+ end
243
+
234
244
  # Duplicate the registry
235
245
  def duplicate_registry
236
246
  globals.each_with_object({}) do |(key, value), result|
237
- result[key] = (value.nil? || value.is_a?(Integer)) ? value : value.dup
247
+ result[key] = value.nil? || value.is_a?(Integer) ? value : value.dup
238
248
  end
239
249
  end
240
250
 
@@ -246,6 +256,14 @@ module RailsMultitenant
246
256
  self.globals = prior_globals
247
257
  end
248
258
 
259
+ # Run a block of code with the given values merged into the current registry
260
+ def with_merged_registry(values = {})
261
+ prior_globals = new_registry(globals.merge(values))
262
+ yield
263
+ ensure
264
+ self.globals = prior_globals
265
+ end
266
+
249
267
  # Prefer .with_isolated_registry to the following two methods.
250
268
  # Note: these methods are intended for use in a manner like .with_isolated_registry,
251
269
  # but in contexts where around semantics are not allowed.
@@ -285,7 +303,6 @@ module RailsMultitenant
285
303
 
286
304
  def globals=(value)
287
305
  Thread.current[:global_context_registry] = value
288
- value
289
306
  end
290
307
  end
291
308
  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
@@ -42,7 +44,7 @@ module RailsMultitenant
42
44
  def validates_multitenant_uniqueness_of(*attr_names)
43
45
  options = attr_names.extract_options!.symbolize_keys
44
46
  existing_scope = Array.wrap(options.delete(:scope))
45
- scope = existing_scope | [ context_entity_id_field ]
47
+ scope = existing_scope | [context_entity_id_field]
46
48
  validates_uniqueness_of(*attr_names, options.merge(scope: scope))
47
49
  end
48
50
 
@@ -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.12.0'
4
+ VERSION = '0.13.0.rc1'
3
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.12.0
4
+ version: 0.13.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Breault
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-26 00:00:00.000000000 Z
11
+ date: 2019-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -120,6 +120,20 @@ dependencies:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
122
  version: 3.8.0
123
+ - !ruby/object:Gem::Dependency
124
+ name: salsify_rubocop
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '='
128
+ - !ruby/object:Gem::Version
129
+ version: 0.63.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.63.0
123
137
  - !ruby/object:Gem::Dependency
124
138
  name: simplecov
125
139
  requirement: !ruby/object:Gem::Requirement
@@ -155,23 +169,7 @@ executables: []
155
169
  extensions: []
156
170
  extra_rdoc_files: []
157
171
  files:
158
- - ".gitignore"
159
- - ".rspec"
160
- - ".ruby-version"
161
- - ".travis.yml"
162
- - Appraisals
163
- - CHANGELOG.md
164
- - CODE_OF_CONDUCT.md
165
- - Gemfile
166
- - README.md
167
- - Rakefile
168
- - bin/console
169
- - bin/setup
170
- - gemfiles/rails_4.2.gemfile
171
- - gemfiles/rails_5.0.gemfile
172
- - gemfiles/rails_5.1.gemfile
173
- - gemfiles/rails_5.2.gemfile
174
- - gemfiles/rails_6.0.gemfile
172
+ - LICENSE.txt
175
173
  - lib/rails_multitenant.rb
176
174
  - lib/rails_multitenant/global_context_registry.rb
177
175
  - lib/rails_multitenant/middleware/extensions.rb
@@ -180,20 +178,6 @@ files:
180
178
  - lib/rails_multitenant/multitenant_model.rb
181
179
  - lib/rails_multitenant/rspec.rb
182
180
  - lib/rails_multitenant/version.rb
183
- - rails_multitenant.gemspec
184
- - spec/be_multitenant_on_matcher_spec.rb
185
- - spec/current_spec.rb
186
- - spec/db/database.yml
187
- - spec/db/schema.rb
188
- - spec/external_item_spec.rb
189
- - spec/external_item_with_optional_org_spec.rb
190
- - spec/global_context_registry_spec.rb
191
- - spec/item_spec.rb
192
- - spec/item_subtype_spec.rb
193
- - spec/item_with_optional_org_spec.rb
194
- - spec/middleware_isolated_context_registry_spec.rb
195
- - spec/rails_multitenant_spec.rb
196
- - spec/spec_helper.rb
197
181
  homepage: https://github.com/salsify/rails-multitenant
198
182
  licenses:
199
183
  - MIT
@@ -209,25 +193,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
193
  version: 2.4.0
210
194
  required_rubygems_version: !ruby/object:Gem::Requirement
211
195
  requirements:
212
- - - ">="
196
+ - - ">"
213
197
  - !ruby/object:Gem::Version
214
- version: '0'
198
+ version: 1.3.1
215
199
  requirements: []
216
200
  rubygems_version: 3.0.4
217
201
  signing_key:
218
202
  specification_version: 4
219
203
  summary: Automatically configures multiple tenants in a Rails environment
220
- test_files:
221
- - spec/spec_helper.rb
222
- - spec/global_context_registry_spec.rb
223
- - spec/external_item_spec.rb
224
- - spec/item_subtype_spec.rb
225
- - spec/current_spec.rb
226
- - spec/item_spec.rb
227
- - spec/external_item_with_optional_org_spec.rb
228
- - spec/db/schema.rb
229
- - spec/db/database.yml
230
- - spec/be_multitenant_on_matcher_spec.rb
231
- - spec/rails_multitenant_spec.rb
232
- - spec/item_with_optional_org_spec.rb
233
- - spec/middleware_isolated_context_registry_spec.rb
204
+ test_files: []
data/.gitignore DELETED
@@ -1,16 +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
15
- /gemfiles/*.gemfile.lock
16
- config
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --format documentation
3
- --require spec_helper
@@ -1 +0,0 @@
1
- 2.6.3
@@ -1,16 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- gemfile:
4
- - gemfiles/rails_4.2.gemfile
5
- - gemfiles/rails_5.0.gemfile
6
- - gemfiles/rails_5.1.gemfile
7
- - gemfiles/rails_5.2.gemfile
8
- - gemfiles/rails_6.0.gemfile
9
- rvm:
10
- - 2.6.3
11
- - 2.5.5
12
- - 2.4.6
13
- matrix:
14
- exclude:
15
- - rvm: 2.4.6
16
- gemfile: gemfiles/rails_6.0.gemfile
data/Appraisals DELETED
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- appraise 'rails-4.2' do
4
- gem 'sqlite3', '~> 1.3.6'
5
- gem 'activerecord', '4.2.11.1'
6
- gem 'activesupport', '4.2.11.1'
7
- end
8
-
9
- appraise 'rails-5.0' do
10
- gem 'sqlite3', '~> 1.3.6'
11
- gem 'activerecord', '5.0.7.2'
12
- gem 'activesupport', '5.0.7.2'
13
- end
14
-
15
- appraise 'rails-5.1' do
16
- gem 'activerecord', '5.1.7'
17
- gem 'activesupport', '5.1.7'
18
- end
19
-
20
- appraise 'rails-5.2' do
21
- gem 'activerecord', '5.2.3'
22
- gem 'activesupport', '5.2.3'
23
- end
24
-
25
- appraise 'rails-6.0' do
26
- gem 'activerecord', '6.0.0.rc2'
27
- gem 'activesupport', '6.0.0.rc2'
28
- end
@@ -1,61 +0,0 @@
1
- # Changelog
2
-
3
- ### 0.12.0
4
- * Drop support for Ruby < 2.4 and Rails < 4.2.
5
- * Add support for Rails 6.
6
-
7
- ### 0.11.0
8
- * Provide shorthands to access `RailsMultitenant::GlobalContextRegistry` methods via `RailsMultitenant`.
9
- For example `RailsMultitenant[:organization_id] = 'some value'` will set that value in the registry.
10
-
11
- ### 0.10.0
12
- * Rails 5.2 support.
13
-
14
- ### 0.9.0
15
- * Modify `Current.current` to return a specified default, when not already initialized, or `nil`
16
- when no default is specified.
17
- * Add `Current.provide_default` to optionally specify a default value for `Current.current`.
18
- * Add `Current.current=` / `Current.current?` / `Current.current!` / `Current.as_current`.
19
-
20
- ### 0.8.0
21
- * Switch usage of Fixnum to Integer for Ruby > 2.4
22
- * Test with multiple Rubies
23
-
24
- ### 0.7.2
25
- * Fix bug that prevents clearing dependents of classes derived from CurrentInstance.
26
-
27
- ### 0.7.1
28
- * Added as_current multi-tenant class method.
29
-
30
- ### 0.7.0
31
- * Add Rack middleware to create a new isolated registry per request.
32
-
33
- ### 0.6.0
34
- * Rails 5.1 support.
35
-
36
- ### 0.5.2
37
- * Optimize `CurrentInstance.current` / `CurrentInstance.current_id` / `CurrentInstance.current=`
38
- / `CurrentInstance.current_id=`.
39
-
40
- ### 0.5.1
41
- * Fix incorrect Rails version dependency in rubygems.org.
42
-
43
- ### 0.5.0
44
- * Add `required` option to `multitenant_on` and `multitenant_on_model`.
45
-
46
- ### 0.4.0
47
- * Fix be_multitenant_on matcher to handle models that don't include the `RailsMultitenant::MultitenantModel` module.
48
- * Fix `context_entity_id_field` to work with inheritance.
49
- * Drop Rails 3.2 and 4.0 support since `unscope` doesn't work propertly with default scopes.
50
-
51
- ### 0.3.1
52
- * Fix strip_<entity>_scope
53
-
54
- ### 0.3.0
55
- * Modify `RailsMultitenant::GlobalContextRegistry#new_registry` to accept an arg
56
- specifying the new registry to set. The previous registry is still returned.
57
-
58
- ### 0.2.0
59
- * Merged [PR 2](https://github.com/salsify/rails-multitenant/pull/2) which adds support for
60
- multi-tenancy based on a foreign key to an external model. As part of this the `multitenant_model_on`
61
- method was renamed to `multitenant_on_model`.
@@ -1,13 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)