multiplicity 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -0
- data/README.md +3 -3
- data/lib/multiplicity.rb +2 -1
- data/lib/multiplicity/middleware/subdomain.rb +51 -0
- data/lib/multiplicity/version.rb +1 -1
- metadata +26 -28
- data/gemfiles/Gemfile.rails-3_2.lock +0 -83
- data/gemfiles/Gemfile.rails-4_2.lock +0 -87
- data/lib/multiplicity/middleware.rb +0 -49
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZmNmOWQ3ZmVlMDgzMDEzZWQwNjNlYmFkOWQ2MGNkZGEyM2NlNGM1Mw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: baae9fd618937beb69067f45db9954aa6cb1514f
|
4
|
+
data.tar.gz: dcdcf7e0febd29000fb8f55b1b65d9f0b2e3df63
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YWZkMzE0ZjljNjRjMjA3MTk1ZDYyZjhhYTdjYTMyMDlmOGI2ODVjNTUxN2Iz
|
11
|
-
YTU0ZjA1ZjYzNTc0YWRkMmU5NWI5MDYzNzU4NDFlNDY5MWY4OTI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NmUwMzFhZGMwYmUzMTc2MDU2ZDhmOGM4N2U2OGZkN2QzNjU2NWJmNDQwNDFk
|
14
|
-
ZDgxOTUzNTA2ZTliYjA4YTc3ZTNlZWNhOGY0M2JhNzM1NmQxNzU4YzkyMTM4
|
15
|
-
MTY3NjMxMDA0ZDkzOTk5NDk4NTQxYzQ2MmFlNWZkMGU5YzQ5MzQ=
|
6
|
+
metadata.gz: c2c98bc0a4c5b74de9138640d39cf025ea564dd374e0f31c9f015d62aee19cf7de79f8a177c37f4740118928259fa6abcca45ed6c1620824ab1e006e73293e8f
|
7
|
+
data.tar.gz: f0250644277faa8f835fd5dc42d6c551dfc0ca8f8b163e561ca7dc905678f100d23e80b1026919da69254b645981f7505a5535d98fcb00d2c3fca357956c1b6b
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Multiplicity
|
2
2
|
|
3
|
-
![build status](https://travis-ci.org/alassek/multiplicity.svg?branch=master)
|
3
|
+
[![build status](https://travis-ci.org/alassek/multiplicity.svg?branch=master)](https://travis-ci.org/alassek/multiplicity)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/multiplicity.svg)](https://rubygems.org/gems/multiplicity)
|
4
5
|
|
5
|
-
Multiplicity is a gem for building
|
6
|
-
with a much less opinionated approach than e.g. [Apartment](https://github.com/influitive/apartment) might entail.
|
6
|
+
Multiplicity is a gem for building multitenant Rack applications, with a much less opinionated approach than e.g. [Apartment](https://github.com/influitive/apartment) might entail.
|
7
7
|
|
8
8
|
The goal of this gem is to provide the simplest tools required to isolate your data, and then get out of your way.
|
9
9
|
|
data/lib/multiplicity.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'multiplicity/version'
|
2
2
|
require 'multiplicity/tenant'
|
3
|
-
require 'multiplicity/middleware'
|
4
3
|
|
5
4
|
module Multiplicity
|
6
5
|
def self.adapter; @adapter; end
|
@@ -24,5 +23,7 @@ module Multiplicity
|
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
26
|
+
# Load Subdomain by default until there are multiple strategies
|
27
|
+
require 'multiplicity/middleware/subdomain'
|
27
28
|
# Always load AR adapter for now, until there is more than one
|
28
29
|
require 'multiplicity/adapters/active_record'
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Multiplicity
|
2
|
+
module Middleware
|
3
|
+
class Subdomain
|
4
|
+
attr_reader :app, :header
|
5
|
+
|
6
|
+
def initialize(app, header = 'HTTP_HOST')
|
7
|
+
@app = app
|
8
|
+
@header = header
|
9
|
+
|
10
|
+
unless defined?(Multiplicity::Adapters)
|
11
|
+
raise RuntimeError, "You must require an adapter to use Multiplicity"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
subdomain = env[header].to_s.sub(/^http(s)?:\/\//, '').sub(/:[0-9]+$/, '')
|
17
|
+
subdomain = subdomain.split('.')[0..-3].join('.').downcase if subdomain.split('.').length > 2
|
18
|
+
subdomain = env.fetch('TENANT', 'localhost') if development?(subdomain)
|
19
|
+
|
20
|
+
if subdomain.length > 0
|
21
|
+
::Multiplicity::Tenant.load(subdomain) or return not_found
|
22
|
+
else
|
23
|
+
return not_found
|
24
|
+
end
|
25
|
+
|
26
|
+
return gone if ::Multiplicity::Tenant.current.archived?
|
27
|
+
|
28
|
+
@app.call(env)
|
29
|
+
ensure
|
30
|
+
::Multiplicity::Tenant.current = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def not_found
|
34
|
+
[404, { 'Content-Type' => 'text/plain', 'Content-Length' => '9' }, ['Not Found']]
|
35
|
+
end
|
36
|
+
|
37
|
+
def gone
|
38
|
+
[410, { 'Content-Type' => 'text/plain', 'Content-Length' => '15' }, ['Tenant archived']]
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def development?(server_name)
|
44
|
+
return true if server_name =~ /^localhost(?:\:[0-9]+)$/
|
45
|
+
return true if server_name =~ /\.local$/
|
46
|
+
return true if server_name =~ /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}(?:\:[0-9]+)$/
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/multiplicity/version.rb
CHANGED
metadata
CHANGED
@@ -1,125 +1,125 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multiplicity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Lassek
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.0.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.0.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
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
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '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
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '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
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: sqlite3
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rspec-expectations
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
description:
|
@@ -129,9 +129,10 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
-
- .gitignore
|
133
|
-
- .rspec
|
134
|
-
- .travis.yml
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CHANGELOG.md
|
135
136
|
- Gemfile
|
136
137
|
- LICENSE.txt
|
137
138
|
- README.md
|
@@ -139,14 +140,12 @@ files:
|
|
139
140
|
- bin/console
|
140
141
|
- bin/setup
|
141
142
|
- gemfiles/Gemfile.rails-3_2
|
142
|
-
- gemfiles/Gemfile.rails-3_2.lock
|
143
143
|
- gemfiles/Gemfile.rails-4_2
|
144
|
-
- gemfiles/Gemfile.rails-4_2.lock
|
145
144
|
- gemfiles/Gemfile.rails-5_0
|
146
145
|
- gemfiles/Gemfile.rails-edge
|
147
146
|
- lib/multiplicity.rb
|
148
147
|
- lib/multiplicity/adapters/active_record.rb
|
149
|
-
- lib/multiplicity/middleware.rb
|
148
|
+
- lib/multiplicity/middleware/subdomain.rb
|
150
149
|
- lib/multiplicity/tenant.rb
|
151
150
|
- lib/multiplicity/version.rb
|
152
151
|
- multiplicity.gemspec
|
@@ -160,19 +159,18 @@ require_paths:
|
|
160
159
|
- lib
|
161
160
|
required_ruby_version: !ruby/object:Gem::Requirement
|
162
161
|
requirements:
|
163
|
-
- -
|
162
|
+
- - ">="
|
164
163
|
- !ruby/object:Gem::Version
|
165
164
|
version: '0'
|
166
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
166
|
requirements:
|
168
|
-
- -
|
167
|
+
- - ">="
|
169
168
|
- !ruby/object:Gem::Version
|
170
169
|
version: '0'
|
171
170
|
requirements: []
|
172
171
|
rubyforge_project:
|
173
|
-
rubygems_version: 2.
|
172
|
+
rubygems_version: 2.5.1
|
174
173
|
signing_key:
|
175
174
|
specification_version: 4
|
176
175
|
summary: Simple multitenancy for rack-based web servers
|
177
176
|
test_files: []
|
178
|
-
has_rdoc:
|
@@ -1,83 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ..
|
3
|
-
specs:
|
4
|
-
multiplicity (0.1.0)
|
5
|
-
rack
|
6
|
-
virtus (>= 1.0.5)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activemodel (3.2.22.2)
|
12
|
-
activesupport (= 3.2.22.2)
|
13
|
-
builder (~> 3.0.0)
|
14
|
-
activerecord (3.2.22.2)
|
15
|
-
activemodel (= 3.2.22.2)
|
16
|
-
activesupport (= 3.2.22.2)
|
17
|
-
arel (~> 3.0.2)
|
18
|
-
tzinfo (~> 0.3.29)
|
19
|
-
activesupport (3.2.22.2)
|
20
|
-
i18n (~> 0.6, >= 0.6.4)
|
21
|
-
multi_json (~> 1.0)
|
22
|
-
arel (3.0.3)
|
23
|
-
axiom-types (0.1.1)
|
24
|
-
descendants_tracker (~> 0.0.4)
|
25
|
-
ice_nine (~> 0.11.0)
|
26
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
27
|
-
builder (3.0.4)
|
28
|
-
coderay (1.1.1)
|
29
|
-
coercible (1.0.0)
|
30
|
-
descendants_tracker (~> 0.0.1)
|
31
|
-
descendants_tracker (0.0.4)
|
32
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
33
|
-
diff-lcs (1.2.5)
|
34
|
-
equalizer (0.0.11)
|
35
|
-
i18n (0.7.0)
|
36
|
-
ice_nine (0.11.2)
|
37
|
-
method_source (0.8.2)
|
38
|
-
multi_json (1.12.1)
|
39
|
-
pry (0.10.4)
|
40
|
-
coderay (~> 1.1.0)
|
41
|
-
method_source (~> 0.8.1)
|
42
|
-
slop (~> 3.4)
|
43
|
-
rack (1.4.7)
|
44
|
-
rake (11.2.2)
|
45
|
-
rspec (3.5.0)
|
46
|
-
rspec-core (~> 3.5.0)
|
47
|
-
rspec-expectations (~> 3.5.0)
|
48
|
-
rspec-mocks (~> 3.5.0)
|
49
|
-
rspec-core (3.5.2)
|
50
|
-
rspec-support (~> 3.5.0)
|
51
|
-
rspec-expectations (3.5.0)
|
52
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
-
rspec-support (~> 3.5.0)
|
54
|
-
rspec-mocks (3.5.0)
|
55
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
-
rspec-support (~> 3.5.0)
|
57
|
-
rspec-support (3.5.0)
|
58
|
-
slop (3.6.0)
|
59
|
-
sqlite3 (1.3.11)
|
60
|
-
thread_safe (0.3.5)
|
61
|
-
tzinfo (0.3.51)
|
62
|
-
virtus (1.0.5)
|
63
|
-
axiom-types (~> 0.1)
|
64
|
-
coercible (~> 1.0)
|
65
|
-
descendants_tracker (~> 0.0, >= 0.0.3)
|
66
|
-
equalizer (~> 0.0, >= 0.0.9)
|
67
|
-
|
68
|
-
PLATFORMS
|
69
|
-
ruby
|
70
|
-
|
71
|
-
DEPENDENCIES
|
72
|
-
activerecord (~> 3.2)
|
73
|
-
bundler
|
74
|
-
multiplicity!
|
75
|
-
pry
|
76
|
-
rack (~> 1.4.5)
|
77
|
-
rake
|
78
|
-
rspec
|
79
|
-
rspec-expectations
|
80
|
-
sqlite3
|
81
|
-
|
82
|
-
BUNDLED WITH
|
83
|
-
1.10.6
|
@@ -1,87 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ..
|
3
|
-
specs:
|
4
|
-
multiplicity (0.1.0)
|
5
|
-
rack
|
6
|
-
virtus (>= 1.0.5)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activemodel (4.2.7)
|
12
|
-
activesupport (= 4.2.7)
|
13
|
-
builder (~> 3.1)
|
14
|
-
activerecord (4.2.7)
|
15
|
-
activemodel (= 4.2.7)
|
16
|
-
activesupport (= 4.2.7)
|
17
|
-
arel (~> 6.0)
|
18
|
-
activesupport (4.2.7)
|
19
|
-
i18n (~> 0.7)
|
20
|
-
json (~> 1.7, >= 1.7.7)
|
21
|
-
minitest (~> 5.1)
|
22
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
23
|
-
tzinfo (~> 1.1)
|
24
|
-
arel (6.0.3)
|
25
|
-
axiom-types (0.1.1)
|
26
|
-
descendants_tracker (~> 0.0.4)
|
27
|
-
ice_nine (~> 0.11.0)
|
28
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
29
|
-
builder (3.2.2)
|
30
|
-
coderay (1.1.1)
|
31
|
-
coercible (1.0.0)
|
32
|
-
descendants_tracker (~> 0.0.1)
|
33
|
-
descendants_tracker (0.0.4)
|
34
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
35
|
-
diff-lcs (1.2.5)
|
36
|
-
equalizer (0.0.11)
|
37
|
-
i18n (0.7.0)
|
38
|
-
ice_nine (0.11.2)
|
39
|
-
json (1.8.3)
|
40
|
-
method_source (0.8.2)
|
41
|
-
minitest (5.9.0)
|
42
|
-
pry (0.10.4)
|
43
|
-
coderay (~> 1.1.0)
|
44
|
-
method_source (~> 0.8.1)
|
45
|
-
slop (~> 3.4)
|
46
|
-
rack (1.6.4)
|
47
|
-
rake (11.2.2)
|
48
|
-
rspec (3.5.0)
|
49
|
-
rspec-core (~> 3.5.0)
|
50
|
-
rspec-expectations (~> 3.5.0)
|
51
|
-
rspec-mocks (~> 3.5.0)
|
52
|
-
rspec-core (3.5.2)
|
53
|
-
rspec-support (~> 3.5.0)
|
54
|
-
rspec-expectations (3.5.0)
|
55
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
-
rspec-support (~> 3.5.0)
|
57
|
-
rspec-mocks (3.5.0)
|
58
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
-
rspec-support (~> 3.5.0)
|
60
|
-
rspec-support (3.5.0)
|
61
|
-
slop (3.6.0)
|
62
|
-
sqlite3 (1.3.11)
|
63
|
-
thread_safe (0.3.5)
|
64
|
-
tzinfo (1.2.2)
|
65
|
-
thread_safe (~> 0.1)
|
66
|
-
virtus (1.0.5)
|
67
|
-
axiom-types (~> 0.1)
|
68
|
-
coercible (~> 1.0)
|
69
|
-
descendants_tracker (~> 0.0, >= 0.0.3)
|
70
|
-
equalizer (~> 0.0, >= 0.0.9)
|
71
|
-
|
72
|
-
PLATFORMS
|
73
|
-
ruby
|
74
|
-
|
75
|
-
DEPENDENCIES
|
76
|
-
activerecord (~> 4.2)
|
77
|
-
bundler
|
78
|
-
multiplicity!
|
79
|
-
pry
|
80
|
-
rack (~> 1.6)
|
81
|
-
rake
|
82
|
-
rspec
|
83
|
-
rspec-expectations
|
84
|
-
sqlite3
|
85
|
-
|
86
|
-
BUNDLED WITH
|
87
|
-
1.10.6
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module Multiplicity
|
2
|
-
class Middleware
|
3
|
-
attr_reader :app, :header
|
4
|
-
|
5
|
-
def initialize(app, header = 'HTTP_HOST')
|
6
|
-
@app = app
|
7
|
-
@header = header
|
8
|
-
|
9
|
-
unless defined?(Multiplicity::Adapters)
|
10
|
-
raise RuntimeError, "You must require an adapter to use Multiplicity"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
subdomain = env[header].to_s.sub(/^http(s)?:\/\//, '').sub(/:[0-9]+$/, '')
|
16
|
-
subdomain = subdomain.split('.')[0..-3].join('.').downcase if subdomain.split('.').length > 2
|
17
|
-
subdomain = env.fetch('TENANT', 'localhost') if development?(subdomain)
|
18
|
-
|
19
|
-
if subdomain.length > 0
|
20
|
-
::Multiplicity::Tenant.load(subdomain) or return not_found
|
21
|
-
else
|
22
|
-
return not_found
|
23
|
-
end
|
24
|
-
|
25
|
-
return gone if ::Multiplicity::Tenant.current.archived?
|
26
|
-
|
27
|
-
@app.call(env)
|
28
|
-
ensure
|
29
|
-
::Multiplicity::Tenant.current = nil
|
30
|
-
end
|
31
|
-
|
32
|
-
def not_found
|
33
|
-
[404, { 'Content-Type' => 'text/plain', 'Content-Length' => '9' }, ['Not Found']]
|
34
|
-
end
|
35
|
-
|
36
|
-
def gone
|
37
|
-
[410, { 'Content-Type' => 'text/plain', 'Content-Length' => '15' }, ['Tenant archived']]
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def development?(server_name)
|
43
|
-
return true if server_name =~ /^localhost(?:\:[0-9]+)$/
|
44
|
-
return true if server_name =~ /\.local$/
|
45
|
-
return true if server_name =~ /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}(?:\:[0-9]+)$/
|
46
|
-
false
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|