tenancy 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +1 -0
- data/Rakefile +2 -2
- data/gemfiles/active_record_41.gemfile +13 -0
- data/gemfiles/mongoid_4.gemfile +1 -1
- data/lib/tenancy/scoping/active_record.rb +9 -1
- data/lib/tenancy/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- metadata +6 -4
- data/.rvmrc +0 -80
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ef48b93df821bf2413626e56eb09d5f2d361c57
|
4
|
+
data.tar.gz: 6f306b0e6aed689b63dcb7e443f0902954b58bb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48e903000a84dcae9fb7ab6e168d006decd9ecc5beb40719800f660a7454d6dfaf610a02efc5568b3c64449f11097aa3f034749a9826e12f20f3a81802b988d0
|
7
|
+
data.tar.gz: b14758e30137dbd75adf79d532098ac922a390d433a446039988863350e60810fbb4f9d8f9f426f356cd860e1c17f0e22be636323e12f836568238c901f06141
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
tenancy
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.1
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ end
|
|
10
10
|
task :default => "spec:all"
|
11
11
|
|
12
12
|
namespace :spec do
|
13
|
-
%w(active_record_40 active_record_32 mongoid_4 mongoid_3).each do |gemfile|
|
13
|
+
%w(active_record_41 active_record_40 active_record_32 mongoid_4 mongoid_3).each do |gemfile|
|
14
14
|
desc "Run Tests against #{gemfile}"
|
15
15
|
task gemfile do
|
16
16
|
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
|
@@ -20,7 +20,7 @@ namespace :spec do
|
|
20
20
|
|
21
21
|
desc "Run Tests against active_record versions"
|
22
22
|
task :all do
|
23
|
-
%w(active_record_40 active_record_32 mongoid_4 mongoid_3).each do |gemfile|
|
23
|
+
%w(active_record_41 active_record_40 active_record_32 mongoid_4 mongoid_3).each do |gemfile|
|
24
24
|
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
|
25
25
|
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rspec"
|
26
26
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gem "activerecord", "~> 4.1.0.rc2", :require => "active_record"
|
4
|
+
gem "coveralls", require: false
|
5
|
+
gem "codeclimate-test-reporter", group: :test, require: nil
|
6
|
+
gem "rspec"
|
7
|
+
gem "database_cleaner"
|
8
|
+
gem "shoulda-matchers"
|
9
|
+
gem "pry"
|
10
|
+
gem "sqlite3"
|
11
|
+
gem "rake"
|
12
|
+
|
13
|
+
gemspec :path => "../"
|
data/gemfiles/mongoid_4.gemfile
CHANGED
@@ -27,7 +27,7 @@ module Tenancy
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def tenant_scope(tenant_names)
|
30
|
-
scope =
|
30
|
+
scope = default_scoped
|
31
31
|
tenants.each do |tenant|
|
32
32
|
next if tenant_names.include?(tenant.name.to_sym)
|
33
33
|
|
@@ -38,6 +38,14 @@ module Tenancy
|
|
38
38
|
scope
|
39
39
|
end
|
40
40
|
|
41
|
+
def default_scoped
|
42
|
+
if ::ActiveRecord::VERSION::MAJOR >= 4 && ::ActiveRecord::VERSION::MINOR >= 1
|
43
|
+
klass.where(nil).default_scoped
|
44
|
+
else
|
45
|
+
klass.where(nil).with_default_scope
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
41
49
|
def validates_uniqueness_in_scope(fields, args={})
|
42
50
|
foreign_keys = tenants.map(&:foreign_key)
|
43
51
|
if args[:scope]
|
data/lib/tenancy/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tenancy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chamnap Chhorn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -48,7 +48,8 @@ files:
|
|
48
48
|
- ".coveralls.yml"
|
49
49
|
- ".gitignore"
|
50
50
|
- ".rspec"
|
51
|
-
- ".
|
51
|
+
- ".ruby-gemset"
|
52
|
+
- ".ruby-version"
|
52
53
|
- ".travis.yml"
|
53
54
|
- CHANGELOG.md
|
54
55
|
- Gemfile
|
@@ -57,6 +58,7 @@ files:
|
|
57
58
|
- Rakefile
|
58
59
|
- gemfiles/active_record_32.gemfile
|
59
60
|
- gemfiles/active_record_40.gemfile
|
61
|
+
- gemfiles/active_record_41.gemfile
|
60
62
|
- gemfiles/mongoid_3.gemfile
|
61
63
|
- gemfiles/mongoid_4.gemfile
|
62
64
|
- lib/tenancy.rb
|
@@ -99,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
101
|
version: 1.8.11
|
100
102
|
requirements: []
|
101
103
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.2.
|
104
|
+
rubygems_version: 2.2.2
|
103
105
|
signing_key:
|
104
106
|
specification_version: 4
|
105
107
|
summary: A simple multitenancy with activerecord/mongoid through scoping
|
data/.rvmrc
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
-
# development environment upon cd'ing into the directory
|
5
|
-
|
6
|
-
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
-
environment_id="ruby-2.1.0@tenancy"
|
8
|
-
|
9
|
-
#
|
10
|
-
# Uncomment the following lines if you want to verify rvm version per project
|
11
|
-
#
|
12
|
-
rvmrc_rvm_version="1.17.10" # 1.10.1 seams as a safe start
|
13
|
-
eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
-
echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
-
return 1
|
16
|
-
}
|
17
|
-
#
|
18
|
-
|
19
|
-
#
|
20
|
-
# Uncomment following line if you want options to be set only for given project.
|
21
|
-
#
|
22
|
-
# PROJECT_JRUBY_OPTS=( --1.9 )
|
23
|
-
#
|
24
|
-
# The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
|
25
|
-
#
|
26
|
-
# chmod +x ${rvm_path}/hooks/after_use_jruby_opts
|
27
|
-
#
|
28
|
-
|
29
|
-
#
|
30
|
-
# First we attempt to load the desired environment directly from the environment
|
31
|
-
# file. This is very fast and efficient compared to running through the entire
|
32
|
-
# CLI and selector. If you want feedback on which environment was used then
|
33
|
-
# insert the word 'use' after --create as this triggers verbose mode.
|
34
|
-
#
|
35
|
-
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
36
|
-
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
37
|
-
then
|
38
|
-
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
39
|
-
|
40
|
-
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
41
|
-
then
|
42
|
-
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
43
|
-
fi
|
44
|
-
else
|
45
|
-
# If the environment file has not yet been created, use the RVM CLI to select.
|
46
|
-
if ! rvm --create use "$environment_id"
|
47
|
-
then
|
48
|
-
echo "Failed to create RVM environment '${environment_id}'."
|
49
|
-
return 1
|
50
|
-
fi
|
51
|
-
fi
|
52
|
-
|
53
|
-
#
|
54
|
-
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
55
|
-
# it be automatically loaded. Uncomment the following and adjust the filename if
|
56
|
-
# necessary.
|
57
|
-
#
|
58
|
-
# filename=".gems"
|
59
|
-
# if [[ -s "$filename" ]]
|
60
|
-
# then
|
61
|
-
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
62
|
-
# fi
|
63
|
-
|
64
|
-
# If you use bundler, this might be useful to you:
|
65
|
-
if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
|
66
|
-
then
|
67
|
-
printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
68
|
-
gem install bundler
|
69
|
-
fi
|
70
|
-
if [[ -s Gemfile ]] && command -v bundle
|
71
|
-
then
|
72
|
-
bundle install
|
73
|
-
fi
|
74
|
-
|
75
|
-
if [[ $- == *i* ]] # check for interactive shells
|
76
|
-
then
|
77
|
-
echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
|
78
|
-
else
|
79
|
-
echo "Using: $GEM_HOME" # don't use colors in interactive shells
|
80
|
-
fi
|