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.
10
11
12
13
|
# File 'lib/apartment/elevators/generic.rb', line 10
def initialize(app, processor = nil)
@app = app
@processor = processor || parse_method
end
|
Instance Method Details
#call(env) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/apartment/elevators/generic.rb', line 15
def call(env)
request = Rack::Request.new(env)
database = @processor.call(request)
Apartment::Database.switch database if database
@app.call(env)
end
|
#deprecation_warning ⇒ Object
43
44
45
|
# File 'lib/apartment/elevators/generic.rb', line 43
def deprecation_warning
warn "[DEPRECATED::Apartment] Use #parse_tenant_name instead of #parse_database_name -> #{self.class.name}"
end
|
#parse_database_name(request) ⇒ Object
25
26
27
28
|
# File 'lib/apartment/elevators/generic.rb', line 25
def parse_database_name(request)
deprecation_warning
parse_tenant_name(request)
end
|
#parse_method ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/apartment/elevators/generic.rb', line 34
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
30
31
32
|
# File 'lib/apartment/elevators/generic.rb', line 30
def parse_tenant_name(request)
raise "Override"
end
|