Class: Houser::Middleware
- Inherits:
-
Object
- Object
- Houser::Middleware
- Defined in:
- lib/houser/middleware.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
7 8 9 10 11 12 13 |
# File 'lib/houser/middleware.rb', line 7 def initialize(app, ={}) @options = @options[:subdomain_column] ||= "subdomain" @options[:class] = Object.const_get([:class_name]) @options[:tld_length] ||= 1 @app = app end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/houser/middleware.rb', line 5 def @options end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/houser/middleware.rb', line 15 def call(env) domain_parts = env['HTTP_HOST'].split('.') if domain_parts.length > 1 + [:tld_length] domain_name = domain_parts[(-[:tld_length] - 1)..-1] subdomain = (domain_parts - domain_name).join('.') find_tenant(env, subdomain) end @app.call(env) end |