class Hijacker::RequestParser

Attributes

host[R]

Public Class Methods

from_env(env) click to toggle source
# File lib/hijacker/request_parser.rb, line 7
def self.from_env(env)
  request = Rack::Request.new(env)
  from_request(request)
end
from_request(request) click to toggle source
# File lib/hijacker/request_parser.rb, line 12
def self.from_request(request)
  new(request.host)
end
new(host) click to toggle source
# File lib/hijacker/request_parser.rb, line 16
def initialize(host)
  @host = host
end

Public Instance Methods

determine_databases() click to toggle source
# File lib/hijacker/request_parser.rb, line 20
def determine_databases
  raise Hijacker::UnparseableURL, "cannot parse '#{host}'" if client.nil?

  Hijacker::Database.find_master_and_sister_for(client)
end

Private Instance Methods

base_client() click to toggle source
# File lib/hijacker/request_parser.rb, line 40
def base_client
  ActiveRecord::Base.configurations.fetch(Rails.env).fetch('database')
end
client() click to toggle source
# File lib/hijacker/request_parser.rb, line 28
def client
  @client ||= do_hijacking? ? client_from_domain_pattern : base_client
end
client_from_domain_pattern() click to toggle source
# File lib/hijacker/request_parser.rb, line 32
def client_from_domain_pattern
  Hijacker.config.
    fetch(:domain_patterns).
    map {|pattern| host.scan(pattern).flatten.first}.
    compact.
    first
end
do_hijacking?() click to toggle source
# File lib/hijacker/request_parser.rb, line 44
def do_hijacking?
  Hijacker.do_hijacking?
end