Class: Innkeeper::Elevators::Generic
- Inherits:
-
Object
- Object
- Innkeeper::Elevators::Generic
- Defined in:
- lib/innkeeper/elevators/generic.rb
Overview
Provides a rack based tenant switching solution based on request
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, processor = nil) ⇒ Generic
constructor
A new instance of Generic.
- #parse_tenant_name(request) ⇒ Object
Constructor Details
#initialize(app, processor = nil) ⇒ Generic
Returns a new instance of Generic.
10 11 12 13 |
# File 'lib/innkeeper/elevators/generic.rb', line 10 def initialize(app, processor = nil) @app = app @processor = processor || method(:parse_tenant_name) end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/innkeeper/elevators/generic.rb', line 15 def call(env) request = Rack::Request.new(env) database = @processor.call(request) if database Innkeeper::Tenant.switch(database) { @app.call(env) } else @app.call(env) end end |
#parse_tenant_name(request) ⇒ Object
27 28 29 |
# File 'lib/innkeeper/elevators/generic.rb', line 27 def parse_tenant_name(request) raise "Override" end |