require 'couch/actions/base' module Couch module Actions class Push < Base def create_database_unless_exists RestClient.put database, nil say "Created database %s" % database rescue RestClient::PreconditionFailed end def push doc = mapper.doc url = url_for(doc["_id"]) say "Pushing to %s..." % url resp = RestClient.put url, doc.to_json response = JSON.parse(resp.body) if response["ok"] rev = response["rev"] File.open File.join(destination_root, "_rev.js"), "w" do |file| file << "#{rev}\n" end say "Pushed %s" % rev else say "Error occured: %s" % response.inspect end rescue RestClient::Conflict say "Conflict! Try to pull first or delete ./_rev." end end end end