Class: Couch::Actions::Push

Inherits:
Base
  • Object
show all
Defined in:
lib/couch/actions/push.rb

Instance Method Summary collapse

Methods inherited from Base

banner

Instance Method Details

#create_database_unless_existsObject



9
10
11
12
13
# File 'lib/couch/actions/push.rb', line 9

def create_database_unless_exists
  RestClient.put DesignDocument.database, nil
  say "Created database %s" % DesignDocument.database
rescue RestClient::PreconditionFailed
end

#pushObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/couch/actions/push.rb', line 15

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