Sha256: 4dd3781ecf01f370e5fbd532a81711e3d4f6d960cb874fdaf80af4d6e4bf377a

Contents?: true

Size: 861 Bytes

Versions: 2

Compression:

Stored size: 861 Bytes

Contents

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"), "w" do |file|
           file << rev
          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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
couch-0.0.2 lib/couch/actions/push.rb
couch-0.0.1 lib/couch/actions/push.rb