Class: Apartment::Elevators::Generic
- Inherits:
-
Object
- Object
- Apartment::Elevators::Generic
- Defined in:
- lib/apartment/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.
11 12 13 14 |
# File 'lib/apartment/elevators/generic.rb', line 11 def initialize(app, processor = nil) @app = app @processor = processor || method(:parse_tenant_name) end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/apartment/elevators/generic.rb', line 16 def call(env) request = Rack::Request.new(env) database = @processor.call(request) if database Apartment::Tenant.switch(database) { @app.call(env) } else @app.call(env) end end |
#parse_tenant_name(_request) ⇒ Object
28 29 30 |
# File 'lib/apartment/elevators/generic.rb', line 28 def parse_tenant_name(_request) raise 'Override' end |