class Fly::Railtie

Public Instance Methods

hijack_database_connection() click to toggle source
# File lib/fly-ruby/railtie.rb, line 2
def hijack_database_connection
  ActiveSupport::Reloader.to_prepare do
    # If we already have a database connection when this initializer runs,
    # we should reconnect to the region-local database. This may need some additional
    # hooks for forking servers to work correctly.
    if defined?(ActiveRecord)
      config = ActiveRecord::Base.connection_db_config.configuration_hash
      ActiveRecord::Base.establish_connection(config.merge(Fly.configuration.regional_database_config))
    end
  end
end
set_debug_response_headers() click to toggle source

Set useful headers for debugging

# File lib/fly-ruby/railtie.rb, line 15
def set_debug_response_headers
  ActiveSupport::Reloader.to_prepare do
    ApplicationController.send(:after_action) do
      response.headers['Fly-Region'] = ENV['FLY_REGION']
    end
  end
end