Sha256: e77a27f1ffa7a3d1498e8f05214bd4c22b5bbd63729d33cdf00a22b2fe17bfbf
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
require 'couch/actions/base' require 'couch/design_document' require 'pathname' require "rest_client" module Couch module Actions class Push < Base def initialize(*args) super @doc = DesignDocument.new end def create_database_unless_exists RestClient.put @doc.database, nil say "Created database %s" % @doc.database rescue RestClient::PreconditionFailed end def push root = Pathname.new(destination_root) filenames = Dir[root.join "**/*"] filenames.map! { |file| Pathname.new file } filenames.map! { |path| path.relative_path_from root } filenames.delete_if { |path| !path.file? } filenames.map!(&:to_s) @doc.read(filenames) do |filename| File.read File.join(destination_root, filename) end say "Pushing to %s" % @doc.url resp = RestClient.put @doc.url, @doc.json response = JSON.parse(resp.body) if response["ok"] @doc.rev = response["rev"] File.open File.join(destination_root, "_rev"), "w" do |file| file << @doc.rev end say "Pushed %s" % @doc.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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
couch-0.2.0 | lib/couch/actions/push.rb |