Class: Multitenancy::Middleware
- Inherits:
-
Object
- Object
- Multitenancy::Middleware
- Defined in:
- lib/multitenancy/middleware.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, header = 'HTTP_HOST') ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, header = 'HTTP_HOST') ⇒ Middleware
Returns a new instance of Middleware.
5 6 7 8 |
# File 'lib/multitenancy/middleware.rb', line 5 def initialize(app, header = 'HTTP_HOST') @app = app @header = header end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
3 4 5 |
# File 'lib/multitenancy/middleware.rb', line 3 def app @app end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
3 4 5 |
# File 'lib/multitenancy/middleware.rb', line 3 def header @header end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/multitenancy/middleware.rb', line 10 def call(env) subdomain = env[header].to_s.sub(/^http(s)?:\/\//, '') subdomain = subdomain.sub(/\.(inteli|patrol)guide\.(net|com)/, '').downcase subdomain = env.fetch('TENANT', 'localhost') if development?(subdomain) if subdomain.length > 0 Tenant.load(subdomain) or return [404, { 'Content-Type' => 'text/html', 'Content-Length' => '9' }, ['Not Found']] end @app.call(env) ensure Tenant.current = nil end |