Skip to content

Instantly share code, notes, and snippets.

@brandon-beacher
Created September 27, 2012 15:41
Show Gist options
  • Save brandon-beacher/3794706 to your computer and use it in GitHub Desktop.
Save brandon-beacher/3794706 to your computer and use it in GitHub Desktop.
class Follower
def self.connect(&block)
if Stage.production?
connect_to_follower(&block)
else
yield
end
end
def self.connect_to_follower(&block)
begin
establish_connection_to_follower
yield
ensure
restore_default_connection
end
end
def self.establish_connection_to_follower
ActiveRecord::Base.establish_connection(production_follower_database_url)
end
def self.production_follower_database_url
ENV['HEROKU_POSTGRESQL_GREEN_URL']
end
def self.restore_default_connection
ActiveRecord::Base.establish_connection(Rails.env)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment