Class: Apartment::Elevators::Generic
- Inherits:
-
Object
- Object
- Apartment::Elevators::Generic
show all
- Defined in:
- lib/apartment/elevators/generic.rb
Overview
Provides a rack based tenant switching solution based on request
Instance Method Summary
collapse
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 || parse_method
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
|
#deprecation_warning ⇒ Object
46
47
48
|
# File 'lib/apartment/elevators/generic.rb', line 46
def deprecation_warning
Apartment::Deprecation.warn "[DEPRECATED::Apartment] Use #parse_tenant_name instead of #parse_database_name -> #{self.class.name}"
end
|
#parse_database_name(request) ⇒ Object
28
29
30
31
|
# File 'lib/apartment/elevators/generic.rb', line 28
def parse_database_name(request)
deprecation_warning
parse_tenant_name(request)
end
|
#parse_method ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/apartment/elevators/generic.rb', line 37
def parse_method
if self.class.instance_methods(false).include? :parse_database_name
deprecation_warning
method(:parse_database_name)
else
method(:parse_tenant_name)
end
end
|
#parse_tenant_name(request) ⇒ Object
33
34
35
|
# File 'lib/apartment/elevators/generic.rb', line 33
def parse_tenant_name(request)
raise "Override"
end
|