rails_multitenant 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 293f8ddc31294eb5091ec683117246dc68d8b2ee
4
- data.tar.gz: ba3050ebc4ecd0abb397137aa5e323d775d47fd2
3
+ metadata.gz: '08f671a9e38be41cc1e23a8f79db4f7d8b2b5a09'
4
+ data.tar.gz: c59f436adebc42b31b325df61f5c74a2227855d4
5
5
  SHA512:
6
- metadata.gz: 9f3fe2d0f2d6a0af2f1e5b2a34873864f1b984a5e8e882a5668e8a6f62be580b8141b017d596246966946a8548eb99ceab4bef13c021a18d0cbb1752d3ba9003
7
- data.tar.gz: 0dae290726903206c204610e1bbc47443ae0cb8475a20c5b2b881327d8bf15471d6b811f3665c30bc420c40c6ec724440e396ecf7d5ba2a20ada00e94d95aabd
6
+ metadata.gz: c0c279650d661914c08bf934a70d6b8cf8043feeb233be653d2721a4fcb3f58cc37632818195ab16fa8dba75b2e45f2587c24698c459f01791b368d212bed7ef
7
+ data.tar.gz: 90e7b9c505b892fa5f8673c51c1556dbe8c6741dbf6f74b994c5b57ce0f23f61fa752ef3fdbd2104122b63d2bf3cd4a5845ac665aafa894b20425c70f1c16ee9
data/.gitignore CHANGED
@@ -7,5 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /log/
10
11
 
11
12
  bundle
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.3
1
+ 2.4.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.7.0
4
+ * Add Rack middleware to create a new isolated registry per request.
5
+
3
6
  ### 0.6.0
4
7
  * Rails 5.1 support.
5
8
 
data/README.md CHANGED
@@ -19,6 +19,10 @@ Or install it yourself as:
19
19
 
20
20
  $ gem install rails_multitenant
21
21
 
22
+ If you're using Rails, there's nothing else you need to do.
23
+
24
+ Otherwise, you need to insert `RailsMultitenant::Middleware::IsolatedContextRegistry` into your middleware stack
25
+
22
26
  ## Usage
23
27
 
24
28
  The gem supports two multi-tenancy strategies:
@@ -26,7 +30,7 @@ The gem supports two multi-tenancy strategies:
26
30
  1. Based on a model attribute, typically a foreign key to an entity owned by another service
27
31
  2. Based on a model association
28
32
 
29
- The gem uses ActiveRecord default scopes to make isolating tenants fairly transparent.
33
+ The gem uses ActiveRecord default scopes to make isolating tenants fairly transparent.
30
34
 
31
35
  ### Multi-tenancy Based on Model Attributes
32
36
 
@@ -4,4 +4,6 @@ require 'active_record'
4
4
  require "rails_multitenant/global_context_registry"
5
5
  require "rails_multitenant/multitenant_model"
6
6
 
7
+ require "rails_multitenant/middleware/extensions"
8
+
7
9
  # rails_multitenant/rspec has to be explicitly included by clients who want to use it
@@ -0,0 +1,5 @@
1
+ require 'rails_multitenant/middleware/isolated_context_registry'
2
+
3
+ if defined?(Rails)
4
+ require 'rails_multitenant/middleware/railtie'
5
+ end
@@ -0,0 +1,15 @@
1
+ module RailsMultitenant
2
+ module Middleware
3
+ class IsolatedContextRegistry
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ GlobalContextRegistry.with_isolated_registry do
10
+ @app.call(env)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module RailsMultitenant
2
+ module Middleware
3
+ class Railtie < ::Rails::Railtie
4
+ initializer "rails_multitenant.middleware" do |app|
5
+ app.config.middleware.insert 0, ::RailsMultitenant::Middleware::IsolatedContextRegistry
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsMultitenant
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -0,0 +1,15 @@
1
+ describe Middleware::IsolatedContextRegistry do
2
+ let(:payload) { [200, {'Content-Type' => 'text/plain'}, ['OK']] }
3
+ let(:app) { lambda { |env| env[2] = GlobalContextRegistry.get(:foo); env } }
4
+ let(:middleware) { described_class.new(app) }
5
+
6
+ describe '.call' do
7
+ specify do
8
+ GlobalContextRegistry.set(:foo, 'bar')
9
+ # Assert that a new global registry is created and read from, where :foo is not set
10
+ expect(middleware.call(payload)).to eq [200, {'Content-Type' => 'text/plain'}, nil]
11
+ # Assert that the outer global context registry is restored
12
+ expect(GlobalContextRegistry.get(:foo)).to eq 'bar'
13
+ end
14
+ end
15
+ 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.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Breault
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-20 00:00:00.000000000 Z
11
+ date: 2017-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -168,6 +168,9 @@ files:
168
168
  - bin/setup
169
169
  - lib/rails_multitenant.rb
170
170
  - lib/rails_multitenant/global_context_registry.rb
171
+ - lib/rails_multitenant/middleware/extensions.rb
172
+ - lib/rails_multitenant/middleware/isolated_context_registry.rb
173
+ - lib/rails_multitenant/middleware/railtie.rb
171
174
  - lib/rails_multitenant/multitenant_model.rb
172
175
  - lib/rails_multitenant/rspec.rb
173
176
  - lib/rails_multitenant/version.rb
@@ -181,6 +184,7 @@ files:
181
184
  - spec/item_spec.rb
182
185
  - spec/item_subtype_spec.rb
183
186
  - spec/item_with_optional_org_spec.rb
187
+ - spec/middleware_isolated_context_registry_spec.rb
184
188
  - spec/spec_helper.rb
185
189
  homepage: https://github.com/salsify/rails-multitenant
186
190
  licenses:
@@ -202,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
206
  version: '0'
203
207
  requirements: []
204
208
  rubyforge_project:
205
- rubygems_version: 2.5.1
209
+ rubygems_version: 2.6.13
206
210
  signing_key:
207
211
  specification_version: 4
208
212
  summary: Automatically configures multiple tenants in a Rails environment
@@ -216,4 +220,5 @@ test_files:
216
220
  - spec/item_spec.rb
217
221
  - spec/item_subtype_spec.rb
218
222
  - spec/item_with_optional_org_spec.rb
223
+ - spec/middleware_isolated_context_registry_spec.rb
219
224
  - spec/spec_helper.rb