mongoid-multitenancy 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +1 -0
- data/.travis.yml +14 -0
- data/Gemfile +13 -1
- data/README.md +1 -1
- data/gemfiles/Gemfile.mongoid-3.0 +16 -0
- data/gemfiles/Gemfile.mongoid-4.0 +16 -0
- data/lib/mongoid/multitenancy.rb +5 -0
- data/lib/mongoid/multitenancy/document.rb +7 -1
- data/lib/mongoid/multitenancy/version.rb +1 -1
- data/mongoid-multitenancy.gemspec +1 -8
- data/spec/spec_helper.rb +10 -4
- data/spec/support/mongoid.rb +30 -0
- metadata +14 -116
- data/Gemfile.lock +0 -55
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTdmMTA4ODVhMTI1Njk1YzMyMGI3OTA5ZDUxYmNkMDkzMmY3MTE4Nw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NGY5ZGFlNmJjMjQ5MzhlOWI4M2NhY2FkMGRkZTk0MjQzNmI3ZDY1MQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDQwNDZmZDc3N2NlYmRiMDJhMzQ0YmVlZDc2NWVmZmY4ZWRkYTY0ZjgzMzVk
|
10
|
+
Yzg1M2I5ZDZkOWM4ZDk1YTJhODk4YWNhNjVkY2I1NTM0MTNjNTRlNDZmNzBi
|
11
|
+
ZTM0NDAzYTM3YmI5NDZhOTI5ODQ4MTEzMGRhNWViOTc0NWZmY2Y=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OTkwYmNkMzIwY2MwNjRhNTIwZTVkNjliNDM0NWZiNzUzNTI3NWQ0YTY3NGZk
|
14
|
+
YjgxYzQ0M2RmZWMzNjYxZGNiNDUzZjNhOTkyNjJlYmU4ZGVlZDA3NmNiZjJi
|
15
|
+
OWFjMzEzYjdjNWY3MTcxZWRjN2JlNzBhMDE5YzVlMzMyOTBhZmU=
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
gem 'mongoid', '~> 4.0.alpha'
|
4
|
+
|
5
|
+
gem 'rake', '~> 10.0'
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'coveralls', :require => false
|
9
|
+
gem 'rspec', '~> 2.12'
|
10
|
+
gem 'yard', '~> 0.8'
|
11
|
+
gem 'mongoid-rspec', '~> 1.5'
|
12
|
+
gem 'database_cleaner', '~> 1.0'
|
13
|
+
end
|
14
|
+
|
3
15
|
# Specify your gem's dependencies in mongoid-multitenancy.gemspec
|
4
|
-
gemspec
|
16
|
+
gemspec
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# mongoid-multitenancy
|
1
|
+
# mongoid-multitenancy [![Build Status](https://travis-ci.org/PerfectMemory/mongoid-multitenancy.png?branch=master)](https://travis-ci.org/PerfectMemory/mongoid-multitenancy.png?branch=master) [![Coverage Status](https://coveralls.io/repos/PerfectMemory/mongoid-multitenancy/badge.png?branch=master)](https://coveralls.io/r/PerfectMemory/mongoid-multitenancy) [![Code Climate](https://codeclimate.com/github/PerfectMemory/mongoid-multitenancy.png)](https://codeclimate.com/github/PerfectMemory/mongoid-multitenancy) [![Dependency Status](https://gemnasium.com/PerfectMemory/mongoid-multitenancy.png)](https://gemnasium.com/PerfectMemory/mongoid-multitenancy)
|
2
2
|
|
3
3
|
mongoid-multitenancy adds the ability to scope [Mongoid](https://github.com/mongoid/mongoid) models to a tenant in a **shared database strategy**. Tenants are represented by a tenant model, such as `Client`. mongoid-multitenancy will help you set the current tenant on each request and ensures all 'tenant models' are always properly scoped to the current tenant: when viewing, searching and creating.
|
4
4
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'mongoid', '~> 3.0'
|
4
|
+
|
5
|
+
gem 'rake', '~> 10.0'
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'coveralls', :require => false
|
9
|
+
gem 'rspec', '~> 2.12'
|
10
|
+
gem 'yard', '~> 0.8'
|
11
|
+
gem 'mongoid-rspec', '~> 1.5'
|
12
|
+
gem 'database_cleaner', '~> 1.0'
|
13
|
+
end
|
14
|
+
|
15
|
+
# Specify your gem's dependencies in mongoid-multitenancy.gemspec
|
16
|
+
gemspec :path => '..'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'mongoid', '~> 4.0.alpha'
|
4
|
+
|
5
|
+
gem 'rake', '~> 10.0'
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'coveralls', :require => false
|
9
|
+
gem 'rspec', '~> 2.12'
|
10
|
+
gem 'yard', '~> 0.8'
|
11
|
+
gem 'mongoid-rspec', '~> 1.5'
|
12
|
+
gem 'database_cleaner', '~> 1.0'
|
13
|
+
end
|
14
|
+
|
15
|
+
# Specify your gem's dependencies in mongoid-multitenancy.gemspec
|
16
|
+
gemspec :path => '..'
|
data/lib/mongoid/multitenancy.rb
CHANGED
@@ -7,6 +7,11 @@ module Mongoid
|
|
7
7
|
module Multitenancy
|
8
8
|
class << self
|
9
9
|
|
10
|
+
# Returns true if using Mongoid 4
|
11
|
+
def mongoid4?
|
12
|
+
Mongoid::VERSION.start_with? '4'
|
13
|
+
end
|
14
|
+
|
10
15
|
# Set the current tenant. Make it Thread aware
|
11
16
|
def current_tenant=(tenant)
|
12
17
|
Thread.current[:current_tenant] = tenant
|
@@ -50,7 +50,13 @@ module Mongoid
|
|
50
50
|
|
51
51
|
# Redefine 'validates_with' to add the tenant scope when using a UniquenessValidator
|
52
52
|
def validates_with(*args, &block)
|
53
|
-
|
53
|
+
validator = if Mongoid::Multitenancy.mongoid4?
|
54
|
+
Validatable::UniquenessValidator
|
55
|
+
else
|
56
|
+
Validations::UniquenessValidator
|
57
|
+
end
|
58
|
+
|
59
|
+
if args.first == validator
|
54
60
|
args.last[:scope] = Array(args.last[:scope]) << self.tenant_field
|
55
61
|
end
|
56
62
|
super(*args, &block)
|
@@ -15,12 +15,5 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Mongoid::Multitenancy::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency('mongoid', '
|
19
|
-
|
20
|
-
gem.add_development_dependency('rake', '~> 10.0')
|
21
|
-
gem.add_development_dependency('rspec', '~> 2.12')
|
22
|
-
gem.add_development_dependency('yard', '~> 0.8')
|
23
|
-
gem.add_development_dependency('mongoid-rspec', '~> 1.5')
|
24
|
-
gem.add_development_dependency('database_cleaner', '~> 1.0')
|
25
|
-
gem.add_development_dependency('redcarpet', '~> 2.2')
|
18
|
+
gem.add_dependency('mongoid', '>= 3.0')
|
26
19
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
1
|
MODELS = File.join(File.dirname(__FILE__), "models")
|
4
2
|
|
5
|
-
require '
|
6
|
-
require '
|
3
|
+
require 'simplecov'
|
4
|
+
require 'coveralls'
|
5
|
+
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
Coveralls::SimpleCov::Formatter
|
9
|
+
]
|
10
|
+
SimpleCov.start
|
7
11
|
|
8
12
|
require 'rspec'
|
9
13
|
require 'mongoid'
|
@@ -11,6 +15,8 @@ require 'mongoid-multitenancy'
|
|
11
15
|
require 'database_cleaner'
|
12
16
|
require 'mongoid-rspec'
|
13
17
|
|
18
|
+
require_relative 'support/mongoid'
|
19
|
+
|
14
20
|
Dir["#{MODELS}/*.rb"].each { |f| require f }
|
15
21
|
|
16
22
|
Mongoid.configure do |config|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module Matchers
|
3
|
+
class HaveIndexForMatcher
|
4
|
+
def matches?(klass)
|
5
|
+
@klass = klass.is_a?(Class) ? klass : klass.class
|
6
|
+
@errors = []
|
7
|
+
|
8
|
+
if Mongoid::VERSION.to_i < 4
|
9
|
+
index_options = @klass.index_options
|
10
|
+
else
|
11
|
+
index_options = Hash[@klass.index_specifications.map{|i| [i.key, i.options]}]
|
12
|
+
end
|
13
|
+
|
14
|
+
unless index_options[@index_fields]
|
15
|
+
@errors.push "no index for #{@index_fields}"
|
16
|
+
else
|
17
|
+
if !@options.nil? && !@options.empty?
|
18
|
+
@options.each do |option, option_value|
|
19
|
+
if index_options[@index_fields][option] != option_value
|
20
|
+
@errors.push "index for #{@index_fields.inspect} with options of #{index_options[@index_fields].inspect}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
@errors.empty?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,128 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-multitenancy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.3.4
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Aymeric Brisse
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
version_requirements: !ruby/object:Gem::Requirement
|
16
|
-
none: false
|
17
|
-
requirements:
|
18
|
-
- - ~>
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '3'
|
21
14
|
name: mongoid
|
22
15
|
requirement: !ruby/object:Gem::Requirement
|
23
|
-
none: false
|
24
16
|
requirements:
|
25
|
-
- -
|
17
|
+
- - ! '>='
|
26
18
|
- !ruby/object:Gem::Version
|
27
|
-
version: '3'
|
28
|
-
prerelease: false
|
19
|
+
version: '3.0'
|
29
20
|
type: :runtime
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
version_requirements: !ruby/object:Gem::Requirement
|
32
|
-
none: false
|
33
|
-
requirements:
|
34
|
-
- - ~>
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: '10.0'
|
37
|
-
name: rake
|
38
|
-
requirement: !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '10.0'
|
44
|
-
prerelease: false
|
45
|
-
type: :development
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
version_requirements: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
|
-
requirements:
|
50
|
-
- - ~>
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '2.12'
|
53
|
-
name: rspec
|
54
|
-
requirement: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
|
-
requirements:
|
57
|
-
- - ~>
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: '2.12'
|
60
|
-
prerelease: false
|
61
|
-
type: :development
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
version_requirements: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
|
-
requirements:
|
66
|
-
- - ~>
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.8'
|
69
|
-
name: yard
|
70
|
-
requirement: !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
|
-
requirements:
|
73
|
-
- - ~>
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0.8'
|
76
|
-
prerelease: false
|
77
|
-
type: :development
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
|
-
requirements:
|
82
|
-
- - ~>
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: '1.5'
|
85
|
-
name: mongoid-rspec
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
|
-
requirements:
|
89
|
-
- - ~>
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version: '1.5'
|
92
|
-
prerelease: false
|
93
|
-
type: :development
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
version_requirements: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
|
-
requirements:
|
98
|
-
- - ~>
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
version: '1.0'
|
101
|
-
name: database_cleaner
|
102
|
-
requirement: !ruby/object:Gem::Requirement
|
103
|
-
none: false
|
104
|
-
requirements:
|
105
|
-
- - ~>
|
106
|
-
- !ruby/object:Gem::Version
|
107
|
-
version: '1.0'
|
108
21
|
prerelease: false
|
109
|
-
type: :development
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
22
|
version_requirements: !ruby/object:Gem::Requirement
|
112
|
-
none: false
|
113
|
-
requirements:
|
114
|
-
- - ~>
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: '2.2'
|
117
|
-
name: redcarpet
|
118
|
-
requirement: !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
23
|
requirements:
|
121
|
-
- -
|
24
|
+
- - ! '>='
|
122
25
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
124
|
-
prerelease: false
|
125
|
-
type: :development
|
26
|
+
version: '3.0'
|
126
27
|
description: MultiTenancy with Mongoid
|
127
28
|
email:
|
128
29
|
- aymeric.brisse@mperfect-memory.com
|
@@ -132,11 +33,13 @@ extra_rdoc_files: []
|
|
132
33
|
files:
|
133
34
|
- .gitignore
|
134
35
|
- .rspec
|
36
|
+
- .travis.yml
|
135
37
|
- Gemfile
|
136
|
-
- Gemfile.lock
|
137
38
|
- LICENSE.TXT
|
138
39
|
- README.md
|
139
40
|
- Rakefile
|
41
|
+
- gemfiles/Gemfile.mongoid-3.0
|
42
|
+
- gemfiles/Gemfile.mongoid-4.0
|
140
43
|
- lib/mongoid-multitenancy.rb
|
141
44
|
- lib/mongoid/multitenancy.rb
|
142
45
|
- lib/mongoid/multitenancy/document.rb
|
@@ -157,36 +60,30 @@ files:
|
|
157
60
|
- spec/mutable_spec.rb
|
158
61
|
- spec/optional_spec.rb
|
159
62
|
- spec/spec_helper.rb
|
63
|
+
- spec/support/mongoid.rb
|
160
64
|
homepage: https://github.com/PerfectMemory/mongoid-multitenancy
|
161
65
|
licenses:
|
162
66
|
- MIT
|
67
|
+
metadata: {}
|
163
68
|
post_install_message:
|
164
69
|
rdoc_options: []
|
165
70
|
require_paths:
|
166
71
|
- lib
|
167
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
168
|
-
none: false
|
169
73
|
requirements:
|
170
74
|
- - ! '>='
|
171
75
|
- !ruby/object:Gem::Version
|
172
|
-
segments:
|
173
|
-
- 0
|
174
|
-
hash: 1046556066794350660
|
175
76
|
version: '0'
|
176
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
-
none: false
|
178
78
|
requirements:
|
179
79
|
- - ! '>='
|
180
80
|
- !ruby/object:Gem::Version
|
181
|
-
segments:
|
182
|
-
- 0
|
183
|
-
hash: 1046556066794350660
|
184
81
|
version: '0'
|
185
82
|
requirements: []
|
186
83
|
rubyforge_project:
|
187
|
-
rubygems_version: 1.
|
84
|
+
rubygems_version: 2.1.11
|
188
85
|
signing_key:
|
189
|
-
specification_version:
|
86
|
+
specification_version: 4
|
190
87
|
summary: Support of a multi-tenant database with Mongoid
|
191
88
|
test_files:
|
192
89
|
- spec/immutable_spec.rb
|
@@ -203,4 +100,5 @@ test_files:
|
|
203
100
|
- spec/mutable_spec.rb
|
204
101
|
- spec/optional_spec.rb
|
205
102
|
- spec/spec_helper.rb
|
103
|
+
- spec/support/mongoid.rb
|
206
104
|
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
mongoid-multitenancy (0.3.4)
|
5
|
-
mongoid (~> 3)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activemodel (3.2.15)
|
11
|
-
activesupport (= 3.2.15)
|
12
|
-
builder (~> 3.0.0)
|
13
|
-
activesupport (3.2.15)
|
14
|
-
i18n (~> 0.6, >= 0.6.4)
|
15
|
-
multi_json (~> 1.0)
|
16
|
-
builder (3.0.4)
|
17
|
-
database_cleaner (1.2.0)
|
18
|
-
diff-lcs (1.2.4)
|
19
|
-
i18n (0.6.5)
|
20
|
-
mongoid (3.1.5)
|
21
|
-
activemodel (~> 3.2)
|
22
|
-
moped (~> 1.4)
|
23
|
-
origin (~> 1.0)
|
24
|
-
tzinfo (~> 0.3.29)
|
25
|
-
mongoid-rspec (1.9.0)
|
26
|
-
mongoid (>= 3.0.1)
|
27
|
-
rake
|
28
|
-
rspec (>= 2.14)
|
29
|
-
moped (1.5.1)
|
30
|
-
multi_json (1.8.2)
|
31
|
-
origin (1.1.0)
|
32
|
-
rake (10.1.0)
|
33
|
-
redcarpet (2.3.0)
|
34
|
-
rspec (2.14.1)
|
35
|
-
rspec-core (~> 2.14.0)
|
36
|
-
rspec-expectations (~> 2.14.0)
|
37
|
-
rspec-mocks (~> 2.14.0)
|
38
|
-
rspec-core (2.14.6)
|
39
|
-
rspec-expectations (2.14.3)
|
40
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
41
|
-
rspec-mocks (2.14.4)
|
42
|
-
tzinfo (0.3.38)
|
43
|
-
yard (0.8.7.2)
|
44
|
-
|
45
|
-
PLATFORMS
|
46
|
-
ruby
|
47
|
-
|
48
|
-
DEPENDENCIES
|
49
|
-
database_cleaner (~> 1.0)
|
50
|
-
mongoid-multitenancy!
|
51
|
-
mongoid-rspec (~> 1.5)
|
52
|
-
rake (~> 10.0)
|
53
|
-
redcarpet (~> 2.2)
|
54
|
-
rspec (~> 2.12)
|
55
|
-
yard (~> 0.8)
|