Class: Innkeeper::Elevators::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/innkeeper/elevators/generic.rb

Overview

Provides a rack based tenant switching solution based on request

Direct Known Subclasses

Domain, HostHash, Subdomain

Instance Method Summary collapse

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