require 'couch/actions/base' require 'couch/design_document' require "rest_client" module Couch module Actions class Push < Base def create_database_unless_exists RestClient.put DesignDocument.database, nil say "Created database %s" % DesignDocument.database rescue RestClient::PreconditionFailed end def push doc = DesignDocument.build_from_filesystem(destination_root) say "Pushing to %s" % DesignDocument.url resp = RestClient.put DesignDocument.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