multitenant 0.4.1 → 1.0.0

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
- SHA1:
3
- metadata.gz: 7febabe4ffdb00857b82fc1a420626f69f8b2e22
4
- data.tar.gz: 7abe0b49276cbd7a93ee897f6d8ae0501dc60908
2
+ SHA256:
3
+ metadata.gz: d442d62b100c49d8981f944f0a01753eb203b511c7dc6fa961294dd040a74ce8
4
+ data.tar.gz: 4559801e2f99045270bd5a84e01c773e7ae63bbc0728fb5e83111b2113c8574f
5
5
  SHA512:
6
- metadata.gz: cdd00f2d57d275367f311219baf2dbc60fcdebe8e0a3478a72a926e87f821684a3bc1d5103f527afd401eb121bdb2b48e2146cb2888306ec49602ba1751fecaf
7
- data.tar.gz: 0129580a641dbca6fb0b50dc96c64f633ffd369e669803e1429c7fc8ff8c6b95448981524a1d852616ddedb13a486f3a54115165a06c4d85cbc11df8c8887966
6
+ metadata.gz: 56daabe10f8062954dfd49dc003314c85d48886351ee4836ee4c9856089745f073279fe4de8fa87b77481768d7d095825a5972fe5d5cb6d99f5e79bd6e008d02
7
+ data.tar.gz: 0a0650fc7f66334106533224452c7d640bd5c344d212b892683843f9c097f421241ed497b77b5232fde53dc9f89b787eead85e5940fb4ef4b28cea9ce2539e65
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.5
1
+ 3.0.1
data/README.md CHANGED
@@ -11,6 +11,9 @@ accidentally leak data to an unintended audience.
11
11
  class User < ActiveRecord::Base
12
12
  belongs_to :tenant
13
13
  belongs_to_multitenant
14
+
15
+ validates :email, uniqueness: true # application-wide uniqueness
16
+ validates :alias, uniqueness: { scope: :tenant_id } # tenant-wide uniqueness
14
17
  end
15
18
 
16
19
  Multitenant.with_tenant current_tenant do
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ require 'bundler/gem_tasks'
3
2
 
4
- require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new('spec')
6
- task :default => :spec
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new('spec')
6
+ task :default => :spec
7
+ rescue LoadError
8
+ end
data/lib/multitenant.rb CHANGED
@@ -3,7 +3,13 @@ require 'active_record'
3
3
  # Multitenant: making cross tenant data leaks a thing of the past...since 2011
4
4
  module Multitenant
5
5
  class << self
6
- attr_accessor :current_tenant
6
+ def current_tenant=(value)
7
+ Thread.current[:current_tenant] = value
8
+ end
9
+
10
+ def current_tenant
11
+ Thread.current[:current_tenant]
12
+ end
7
13
 
8
14
  # execute a block scoped to the current tenant
9
15
  # unsets the current tenant after execution
@@ -1,3 +1,3 @@
1
1
  module Multitenant
2
- VERSION = "0.4.1"
2
+ VERSION = '1.0.0'
3
3
  end
data/multitenant.gemspec CHANGED
@@ -17,9 +17,9 @@ Gem::Specification.new do |s|
17
17
  s.add_dependency(%q<activerecord>, ['>= 3.1'])
18
18
 
19
19
  s.add_development_dependency('rake')
20
- s.add_development_dependency('sqlite3', ["~> 1.3.3"])
21
- s.add_development_dependency('rspec', ['~> 2.6.0'])
22
- s.add_development_dependency('rspec-core', ['~> 2.6.4'])
20
+ s.add_development_dependency('sqlite3', ["~> 1.4.1"])
21
+ s.add_development_dependency('rspec', ['~> 3.0'])
22
+ s.add_development_dependency('rspec-core', ['~> 3.0'])
23
23
 
24
24
  s.files = `git ls-files`.split("\n")
25
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -45,6 +45,15 @@ describe Multitenant do
45
45
  it { Multitenant.current_tenant == :foo }
46
46
  end
47
47
 
48
+ describe '#current_tenant=' do
49
+ it 'is threadsafe' do
50
+ Multitenant.current_tenant = :old_tenant
51
+ overwriter = Thread.new { Multitenant.current_tenant = :new_tenant }
52
+ overwriter.join
53
+ Multitenant.current_tenant.should == :old_tenant
54
+ end
55
+ end
56
+
48
57
  describe 'Multitenant.with_tenant block' do
49
58
  before do
50
59
  @executed = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multitenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Sonnek
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-19 00:00:00.000000000 Z
11
+ date: 2021-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -44,42 +44,42 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.3.3
47
+ version: 1.4.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.3.3
54
+ version: 1.4.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 2.6.0
61
+ version: '3.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 2.6.0
68
+ version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-core
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 2.6.4
75
+ version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 2.6.4
82
+ version: '3.0'
83
83
  description: never let an unscoped Model.all accidentally leak data to an unintended
84
84
  audience.
85
85
  email:
@@ -106,7 +106,7 @@ files:
106
106
  homepage: http://github.com/wireframe/multitenant
107
107
  licenses: []
108
108
  metadata: {}
109
- post_install_message:
109
+ post_install_message:
110
110
  rdoc_options: []
111
111
  require_paths:
112
112
  - lib
@@ -121,9 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  requirements: []
124
- rubyforge_project: multitenant
125
- rubygems_version: 2.2.2
126
- signing_key:
124
+ rubygems_version: 3.2.15
125
+ signing_key:
127
126
  specification_version: 4
128
127
  summary: scope database queries to current tenant
129
128
  test_files: