Permalink
Browse files

Merge remote branch 'vinova/master'

Conflicts:
	README.md
	lib/heroku/command/mongo.rb
  • Loading branch information...
2 parents d922a22 + 631d185 commit 445d82597c18e6b75c67d7ed46e95072d6330d7e @matthewford matthewford committed Nov 24, 2010
Showing with 33 additions and 18 deletions.
  1. +3 −6 README.md
  2. +30 −12 lib/heroku/command/mongo.rb
View
@@ -8,16 +8,13 @@ somewhere else, just make sure you have access from your local machine.
## About this fork
-I've fixed a bug when running 1.9.2, "can't modify frozen string". While figuering out how to fix it, I created a new gemset in rvm and built a Gemfile describing the gems needed. I replaced baconmocha with rspec and mocha, for no other reason that I struggled getting bacon to run (and I don't real care much about the test runner, I care about tests). All tests run >spec spec. Oh yeah, I've added the mongodb default port in the tests.
-
Thanks to pedro for creating the plugin!
+This merges a few forks that are out there.
+
## Installation
- # From this ruby 1.9.2 fork
- $ heroku plugins:install http://github.com:oma/heroku-mongo-sync.git
- # or from the pedro's original
- $ heroku plugins:install http://github.com/pedro/heroku-mongo-sync.git
+ $ heroku plugins:install http://github.com/bitzesty/heroku-mongo-sync.git
## Config
@@ -9,14 +9,14 @@ def initialize(*args)
end
def push
- display "THIS WILL REPLACE ALL DATA for #{app} ON #{heroku_mongo_uri.host} WITH #{local_mongo_uri.host} db #{local_db_name}"
+ display "THIS WILL REPLACE ALL DATA for #{app} ON #{heroku_mongo_uri} WITH #{local_mongo_uri} db #{local_db_name}"
display "Are you sure? (y/n) ", false
return unless ask.downcase == 'y'
transfer(local_mongo_uri, heroku_mongo_uri)
end
def pull
- display "Replacing the #{local_db_name} db at #{local_mongo_uri.host} with #{heroku_mongo_uri.host} #{app}"
+ display "Replacing the #{mongoid_database || app} db at #{local_mongo_uri} with #{heroku_mongo_uri}"
transfer(heroku_mongo_uri, local_mongo_uri)
end
@@ -67,23 +67,41 @@ def heroku_mongo_uri
error("Could not find the MONGO_URL for #{app}") unless url
make_uri(url)
end
-
- def local_db_name
- URI.parse(local_mongo_url).path.gsub("/","")
+
+ def mongoid_database
+ @@mongoid_database if mongoid_uri
end
-
- def local_mongo_url
- ENV['MONGO_URL'] || "mongodb://localhost:27017/#{app}"
+
+ def mongoid_uri
+ @@mongoid_uri ||= mongoid_uri_
end
-
+
+ def mongoid_uri_
+ # Try to use mongo development database name in mongoid.yml config file
+ begin
+ config = YAML::load_file('config/mongoid.yml')['development']
+ @@mongoid_database = config['database']
+ if @@mongoid_database
+ port = config['port'] || '27017'
+ host = config['host'] || 'localhost'
+ username = config['username']
+ password = config['password']
+ uri = "mongodb://"
+ uri << "#{username}:#{password}@" if username && password
+ uri << "#{host}:#{port}/#{@@mongoid_database}"
+ return uri
+ end
+ rescue StandardError => e
+ end
+ end
+
def local_mongo_uri
- url = local_mongo_url
+ url = mongoid_uri || ENV['MONGO_URL'] || "mongodb://localhost:27017/#{app}"
make_uri(url)
end
def make_uri(url)
- url = url.gsub('local.mongohq.com', 'mongohq.com')
- uri = URI.parse(url)
+ uri = URI.parse(url.gsub('local.mongohq.com', 'mongohq.com'))
raise URI::InvalidURIError unless uri.host
uri
rescue URI::InvalidURIError

0 comments on commit 445d825

Please sign in to comment.