Class: Apartment::Elevators::HostHash

Inherits:
Generic
  • Object
show all
Defined in:
lib/apartment/elevators/host_hash.rb

Overview

Provides a rack based db switching solution based on hosts

Uses a hash to find the corresponding database name for the host

Instance Method Summary collapse

Methods inherited from Generic

#call

Constructor Details

#initialize(app, hash = {}, processor = nil) ⇒ HostHash

Returns a new instance of HostHash.



9
10
11
12
# File 'lib/apartment/elevators/host_hash.rb', line 9

def initialize(app, hash = {}, processor = nil)
  super app, processor
  @hash = hash
end

Instance Method Details

#parse_database_name(request) ⇒ Object

Raises:



14
15
16
17
18
19
# File 'lib/apartment/elevators/host_hash.rb', line 14

def parse_database_name(request)
  raise DatabaseNotFound,
    "Cannot find database for host #{request.host}" unless @hash.has_key?(request.host)

  @hash[request.host]
end