Module: Hijacker::ControllerMethods::Instance

Included in:
ActionController::Base
Defined in:
lib/hijacker/controller_methods.rb

Instance Method Summary collapse

Instance Method Details

#determine_databasesObject

Returns 2-member array of the main database to connect to, and the sister (sister will be nil if no master is found, which means we are on the master).



22
23
24
# File 'lib/hijacker/controller_methods.rb', line 22

def determine_databases
  Hijacker::RequestParser.from_request(request).determine_databases
end

#hijack_connectionObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/hijacker/controller_methods.rb', line 4

def hijack_connection
  master, sister = determine_databases

  Hijacker.connect(master, sister)

  return true
rescue Hijacker::InvalidDatabase => e
  render_invalid_db

  # If we've encountered a bad database connection, we don't want
  # to continue rendering the rest of the before_filters on this, which it will
  # try to do even when just rendering the bit of text above. If any filters
  # return false, though, it will halt the filter chain.
  return false
end

#render_invalid_dbObject



26
27
28
29
# File 'lib/hijacker/controller_methods.rb', line 26

def render_invalid_db
  render :text => "You do not appear to have an account with us (#{request.host})",
    :status => 404
end