Permalink
Browse files

Store the MongoDB connection params in a YAML file, not an ENV var

  • Loading branch information...
1 parent e0c349c commit fd51b469bfc521bc48f91adc57df32bf661d2eea @leocassarani committed Apr 27, 2012
Showing with 10 additions and 8 deletions.
  1. +2 −1 .gitignore
  2. +2 −1 lib/timetable/application.rb
  3. +6 −6 lib/timetable/database.rb
View
@@ -1,3 +1,4 @@
.DS_Store
.rvmrc
-config/deploy.rb
+config/deploy.rb
+config/database.yml
@@ -43,7 +43,8 @@ class Application < Sinatra::Base
# If the preset doesn't exist (e.g. because the user took all the
# modules), then give them a default url of the form course/yoe
name = preset.name || "#{params[:course]}/#{params[:yoe]}"
- host = ENV.fetch('TIMETABLE_HOST', "localhost:9393")
+ host = request.host
+ host += ":9393" if host == "localhost"
@url = "webcal://#{host}/#{name}"
@lightbox = true
View
@@ -4,19 +4,19 @@ module Timetable
class Database
# Establish a connection to our MongoHQ instance
def initialize(collection)
- if ENV['MONGOHQ_URL']
- uri = URI.parse(ENV['MONGOHQ_URL'])
-
+ mongo_url = Config.read('mongo_url')
+ if mongo_url
begin
- @conn = Mongo::Connection.from_uri(ENV['MONGOHQ_URL'])
+ @conn = Mongo::Connection.from_uri(mongo_url)
rescue Mongo::MongoArgumentError => e
raise RuntimeError, "Cannot connect to the database"
end
+ uri = URI.parse(mongo_url)
db = @conn.db(uri.path.gsub(/^\//, ''))
else
- local = "mongodb://localhost:27017"
- @conn = Mongo::Connection.from_uri(local)
+ localhost = "mongodb://localhost:27017"
+ @conn = Mongo::Connection.from_uri(localhost)
db = @conn.db('timetable')
end

0 comments on commit fd51b46

Please sign in to comment.