multitenant 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ # test files
7
+ spec/*.log
8
+ spec/*.sqlite3
9
+
data/.rspec CHANGED
@@ -1 +1,3 @@
1
1
  --color
2
+ --format documentation
3
+ --backtrace
data/Gemfile CHANGED
@@ -1,14 +1,4 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- gemspec
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "rspec", "~> 2.3.0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.2"
12
- gem "rcov", ">= 0"
13
- gem 'sqlite3', '~> 1.3.3'
14
- end
3
+ # Specify your gem's dependencies in multitenant.gemspec
4
+ gemspec
data/README.rdoc CHANGED
@@ -5,17 +5,17 @@ When building multitenant applications, never let an unscoped Model.all accident
5
5
  == Usage
6
6
 
7
7
  class User < ActiveRecord::Base
8
- belongs_to :company
9
- belongs_to_tenant :company
8
+ belongs_to :tenant
9
+ belongs_to_multitenant
10
10
  end
11
11
 
12
- Multitenant.with_tenant current_company do
12
+ Multitenant.with_tenant current_tenant do
13
13
  # queries within this block are automatically
14
- # scoped to the current company
14
+ # scoped to the current tenant
15
15
  User.all
16
16
 
17
17
  # new objects created within this block are automatically
18
- # assigned to the current company
18
+ # assigned to the current tenant
19
19
  User.create :name => 'Bob'
20
20
  end
21
21
 
data/Rakefile CHANGED
@@ -1,49 +1,6 @@
1
- require 'rubygems'
2
1
  require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
2
+ Bundler::GemHelper.install_tasks
11
3
 
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "multitenant"
16
- gem.homepage = "http://github.com/wireframe/multitenant"
17
- gem.license = "MIT"
18
- gem.summary = %Q{scope database queries to current tenant}
19
- gem.description = %Q{never let an unscoped Model.all accidentally leak data to an unintended audience.}
20
- gem.email = "ryan@codecrate.com"
21
- gem.authors = ["Ryan Sonnek"]
22
- gem.add_runtime_dependency "activerecord", "~> 3.0.3"
23
- gem.add_runtime_dependency "activesupport", "~> 3.0.3"
24
- gem.add_runtime_dependency 'dynamic_default_scoping', '~> 0.0.3'
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- require 'rspec/core'
29
4
  require 'rspec/core/rake_task'
30
- RSpec::Core::RakeTask.new(:spec) do |spec|
31
- spec.pattern = FileList['spec/**/*_spec.rb']
32
- end
33
-
34
- RSpec::Core::RakeTask.new(:rcov) do |spec|
35
- spec.pattern = 'spec/**/*_spec.rb'
36
- spec.rcov = true
37
- end
38
-
5
+ RSpec::Core::RakeTask.new('spec')
39
6
  task :default => :spec
40
-
41
- require 'rake/rdoctask'
42
- Rake::RDocTask.new do |rdoc|
43
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
-
45
- rdoc.rdoc_dir = 'rdoc'
46
- rdoc.title = "multitenant #{version}"
47
- rdoc.rdoc_files.include('README*')
48
- rdoc.rdoc_files.include('lib/**/*.rb')
49
- end
data/lib/multitenant.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require 'active_record'
2
- require 'active_support/all'
3
- require 'dynamic_default_scoping'
4
2
 
5
3
  # Multitenant: making cross tenant data leaks a thing of the past...since 2011
6
4
  module Multitenant
@@ -20,16 +18,14 @@ module Multitenant
20
18
  module ActiveRecordExtensions
21
19
  # configure the current model to automatically query and populate objects based on the current tenant
22
20
  # see Multitenant#current_tenant
23
- def belongs_to_tenant(association = :tenant)
24
- include DynamicDefaultScoping
21
+ def belongs_to_multitenant(association = :tenant)
25
22
  reflection = reflect_on_association association
26
23
  before_validation Proc.new {|m|
27
24
  return unless Multitenant.current_tenant
28
25
  m.send "#{association}=".to_sym, Multitenant.current_tenant
29
26
  }, :on => :create
30
- default_scope :scoped_to_tenant, lambda {
31
- return {} unless Multitenant.current_tenant
32
- where({reflection.primary_key_name => Multitenant.current_tenant.id})
27
+ default_scope lambda {
28
+ where({reflection.primary_key_name => Multitenant.current_tenant.id}) if Multitenant.current_tenant
33
29
  }
34
30
  end
35
31
  end
@@ -0,0 +1,3 @@
1
+ module Multitenant
2
+ VERSION = "0.3.0"
3
+ end
data/multitenant.gemspec CHANGED
@@ -1,94 +1,25 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "multitenant/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{multitenant}
8
- s.version = "0.2.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Ryan Sonnek"]
12
- s.date = %q{2011-02-07}
6
+ s.name = "multitenant"
7
+ s.version = Multitenant::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ryan Sonnek"]
10
+ s.email = ["ryan@codecrate.com"]
11
+ s.homepage = "http://github.com/wireframe/multitenant"
12
+ s.summary = %q{scope database queries to current tenant}
13
13
  s.description = %q{never let an unscoped Model.all accidentally leak data to an unintended audience.}
14
- s.email = %q{ryan@codecrate.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".rspec",
22
- "Gemfile",
23
- "LICENSE.txt",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "lib/multitenant.rb",
28
- "multitenant.gemspec",
29
- "spec/database.yml",
30
- "spec/multitenant_spec.rb",
31
- "spec/spec_helper.rb"
32
- ]
33
- s.homepage = %q{http://github.com/wireframe/multitenant}
34
- s.licenses = ["MIT"]
35
- s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.5.0}
37
- s.summary = %q{scope database queries to current tenant}
38
- s.test_files = [
39
- "spec/multitenant_spec.rb",
40
- "spec/spec_helper.rb"
41
- ]
42
14
 
43
- if s.respond_to? :specification_version then
44
- s.specification_version = 3
15
+ s.rubyforge_project = "multitenant"
45
16
 
46
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- s.add_runtime_dependency(%q<multitenant>, [">= 0"])
48
- s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
49
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
51
- s.add_development_dependency(%q<rcov>, [">= 0"])
52
- s.add_development_dependency(%q<sqlite3>, ["~> 1.3.3"])
53
- s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
54
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
55
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
56
- s.add_development_dependency(%q<rcov>, [">= 0"])
57
- s.add_development_dependency(%q<sqlite3>, ["~> 1.3.3"])
58
- s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.3"])
59
- s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.3"])
60
- s.add_runtime_dependency(%q<dynamic_default_scoping>, ["~> 0.0.3"])
61
- else
62
- s.add_dependency(%q<multitenant>, [">= 0"])
63
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
64
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
66
- s.add_dependency(%q<rcov>, [">= 0"])
67
- s.add_dependency(%q<sqlite3>, ["~> 1.3.3"])
68
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
69
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
70
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
71
- s.add_dependency(%q<rcov>, [">= 0"])
72
- s.add_dependency(%q<sqlite3>, ["~> 1.3.3"])
73
- s.add_dependency(%q<activerecord>, ["~> 3.0.3"])
74
- s.add_dependency(%q<activesupport>, ["~> 3.0.3"])
75
- s.add_dependency(%q<dynamic_default_scoping>, ["~> 0.0.3"])
76
- end
77
- else
78
- s.add_dependency(%q<multitenant>, [">= 0"])
79
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
80
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
81
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
82
- s.add_dependency(%q<rcov>, [">= 0"])
83
- s.add_dependency(%q<sqlite3>, ["~> 1.3.3"])
84
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
85
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
86
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
87
- s.add_dependency(%q<rcov>, [">= 0"])
88
- s.add_dependency(%q<sqlite3>, ["~> 1.3.3"])
89
- s.add_dependency(%q<activerecord>, ["~> 3.0.3"])
90
- s.add_dependency(%q<activesupport>, ["~> 3.0.3"])
91
- s.add_dependency(%q<dynamic_default_scoping>, ["~> 0.0.3"])
92
- end
93
- end
17
+ s.add_dependency(%q<activerecord>, ['~>3.1.rc1'])
18
+ s.add_development_dependency(%q<sqlite3>, ["~> 1.3.3"])
19
+ s.add_development_dependency(%q<rspec>, ['~>2.6.0'])
94
20
 
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  ActiveRecord::Schema.define(:version => 1) do
4
4
  create_table :companies, :force => true do |t|
@@ -26,7 +26,7 @@ class Company < ActiveRecord::Base
26
26
  end
27
27
  class User < ActiveRecord::Base
28
28
  belongs_to :company
29
- belongs_to_tenant :company
29
+ belongs_to_multitenant :company
30
30
  end
31
31
 
32
32
  class Tenant < ActiveRecord::Base
@@ -34,7 +34,7 @@ class Tenant < ActiveRecord::Base
34
34
  end
35
35
  class Item < ActiveRecord::Base
36
36
  belongs_to :tenant
37
- belongs_to_tenant
37
+ belongs_to_multitenant
38
38
  end
39
39
 
40
40
  describe Multitenant do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multitenant
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Sonnek
@@ -15,88 +15,29 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-07 00:00:00 -06:00
19
- default_executable:
18
+ date: 2011-05-23 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- name: multitenant
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
21
+ name: activerecord
32
22
  prerelease: false
33
- type: :runtime
34
- requirement: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: rspec
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
38
24
  none: false
39
25
  requirements:
40
26
  - - ~>
41
27
  - !ruby/object:Gem::Version
42
- hash: 3
28
+ hash: 15424223
43
29
  segments:
44
- - 2
45
30
  - 3
46
- - 0
47
- version: 2.3.0
48
- prerelease: false
49
- type: :development
50
- requirement: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: bundler
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 23
59
- segments:
60
31
  - 1
61
- - 0
62
- - 0
63
- version: 1.0.0
64
- prerelease: false
65
- type: :development
66
- requirement: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: jeweler
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
72
- - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 7
75
- segments:
32
+ - rc
76
33
  - 1
77
- - 5
78
- - 2
79
- version: 1.5.2
80
- prerelease: false
81
- type: :development
82
- requirement: *id004
83
- - !ruby/object:Gem::Dependency
84
- name: rcov
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
86
- none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
94
- prerelease: false
95
- type: :development
96
- requirement: *id005
34
+ version: 3.1.rc1
35
+ type: :runtime
36
+ version_requirements: *id001
97
37
  - !ruby/object:Gem::Dependency
98
38
  name: sqlite3
99
- version_requirements: &id006 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
100
41
  none: false
101
42
  requirements:
102
43
  - - ~>
@@ -107,161 +48,50 @@ dependencies:
107
48
  - 3
108
49
  - 3
109
50
  version: 1.3.3
110
- prerelease: false
111
51
  type: :development
112
- requirement: *id006
52
+ version_requirements: *id002
113
53
  - !ruby/object:Gem::Dependency
114
54
  name: rspec
115
- version_requirements: &id007 !ruby/object:Gem::Requirement
116
- none: false
117
- requirements:
118
- - - ~>
119
- - !ruby/object:Gem::Version
120
- hash: 3
121
- segments:
122
- - 2
123
- - 3
124
- - 0
125
- version: 2.3.0
126
55
  prerelease: false
127
- type: :development
128
- requirement: *id007
129
- - !ruby/object:Gem::Dependency
130
- name: bundler
131
- version_requirements: &id008 !ruby/object:Gem::Requirement
56
+ requirement: &id003 !ruby/object:Gem::Requirement
132
57
  none: false
133
58
  requirements:
134
59
  - - ~>
135
60
  - !ruby/object:Gem::Version
136
61
  hash: 23
137
62
  segments:
138
- - 1
139
- - 0
140
- - 0
141
- version: 1.0.0
142
- prerelease: false
143
- type: :development
144
- requirement: *id008
145
- - !ruby/object:Gem::Dependency
146
- name: jeweler
147
- version_requirements: &id009 !ruby/object:Gem::Requirement
148
- none: false
149
- requirements:
150
- - - ~>
151
- - !ruby/object:Gem::Version
152
- hash: 7
153
- segments:
154
- - 1
155
- - 5
156
63
  - 2
157
- version: 1.5.2
158
- prerelease: false
159
- type: :development
160
- requirement: *id009
161
- - !ruby/object:Gem::Dependency
162
- name: rcov
163
- version_requirements: &id010 !ruby/object:Gem::Requirement
164
- none: false
165
- requirements:
166
- - - ">="
167
- - !ruby/object:Gem::Version
168
- hash: 3
169
- segments:
64
+ - 6
170
65
  - 0
171
- version: "0"
172
- prerelease: false
173
- type: :development
174
- requirement: *id010
175
- - !ruby/object:Gem::Dependency
176
- name: sqlite3
177
- version_requirements: &id011 !ruby/object:Gem::Requirement
178
- none: false
179
- requirements:
180
- - - ~>
181
- - !ruby/object:Gem::Version
182
- hash: 29
183
- segments:
184
- - 1
185
- - 3
186
- - 3
187
- version: 1.3.3
188
- prerelease: false
66
+ version: 2.6.0
189
67
  type: :development
190
- requirement: *id011
191
- - !ruby/object:Gem::Dependency
192
- name: activerecord
193
- version_requirements: &id012 !ruby/object:Gem::Requirement
194
- none: false
195
- requirements:
196
- - - ~>
197
- - !ruby/object:Gem::Version
198
- hash: 1
199
- segments:
200
- - 3
201
- - 0
202
- - 3
203
- version: 3.0.3
204
- prerelease: false
205
- type: :runtime
206
- requirement: *id012
207
- - !ruby/object:Gem::Dependency
208
- name: activesupport
209
- version_requirements: &id013 !ruby/object:Gem::Requirement
210
- none: false
211
- requirements:
212
- - - ~>
213
- - !ruby/object:Gem::Version
214
- hash: 1
215
- segments:
216
- - 3
217
- - 0
218
- - 3
219
- version: 3.0.3
220
- prerelease: false
221
- type: :runtime
222
- requirement: *id013
223
- - !ruby/object:Gem::Dependency
224
- name: dynamic_default_scoping
225
- version_requirements: &id014 !ruby/object:Gem::Requirement
226
- none: false
227
- requirements:
228
- - - ~>
229
- - !ruby/object:Gem::Version
230
- hash: 25
231
- segments:
232
- - 0
233
- - 0
234
- - 3
235
- version: 0.0.3
236
- prerelease: false
237
- type: :runtime
238
- requirement: *id014
68
+ version_requirements: *id003
239
69
  description: never let an unscoped Model.all accidentally leak data to an unintended audience.
240
- email: ryan@codecrate.com
70
+ email:
71
+ - ryan@codecrate.com
241
72
  executables: []
242
73
 
243
74
  extensions: []
244
75
 
245
- extra_rdoc_files:
246
- - LICENSE.txt
247
- - README.rdoc
76
+ extra_rdoc_files: []
77
+
248
78
  files:
249
79
  - .document
80
+ - .gitignore
250
81
  - .rspec
251
82
  - Gemfile
252
83
  - LICENSE.txt
253
84
  - README.rdoc
254
85
  - Rakefile
255
- - VERSION
256
86
  - lib/multitenant.rb
87
+ - lib/multitenant/version.rb
257
88
  - multitenant.gemspec
258
89
  - spec/database.yml
259
90
  - spec/multitenant_spec.rb
260
91
  - spec/spec_helper.rb
261
- has_rdoc: true
262
92
  homepage: http://github.com/wireframe/multitenant
263
- licenses:
264
- - MIT
93
+ licenses: []
94
+
265
95
  post_install_message:
266
96
  rdoc_options: []
267
97
 
@@ -287,11 +117,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
287
117
  version: "0"
288
118
  requirements: []
289
119
 
290
- rubyforge_project:
291
- rubygems_version: 1.5.0
120
+ rubyforge_project: multitenant
121
+ rubygems_version: 1.8.1
292
122
  signing_key:
293
123
  specification_version: 3
294
124
  summary: scope database queries to current tenant
295
125
  test_files:
126
+ - spec/database.yml
296
127
  - spec/multitenant_spec.rb
297
128
  - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.0