Permalink
Browse files

Implementing __ and ways of saving documents

  • Loading branch information...
1 parent 9c7ae3c commit fe7386f63975b57eff8e4f77c45e548af8bfb5a4 @sreeix committed Feb 28, 2011
Showing with 9 additions and 4 deletions.
  1. +6 −2 lib/couchup.rb
  2. +3 −2 lib/couchup/couchup.rb
View
@@ -8,13 +8,17 @@
Couchup::Commands.constants.each do |c|
instance_eval "
+ def last_result
+ Couchup::Couchup.last_result
+ end
+ alias __ last_result
def #{c.underscore}(*args)
begin
instance = Couchup::Commands.const_get(:#{c}).new
- instance.run(*args)
+ Couchup::Couchup.last_result = instance.run(*args)
rescue
puts $!.inspect
- puts $!.backtrace if Couchup.debug?
+ puts $!.backtrace if Couchup::Couchup.debug?
end
end"
end
View
@@ -2,6 +2,7 @@ module Couchup
class Couchup
class << self
attr_accessor :port, :host
+ attr_accessor :last_result
def server
@server ||= CouchRest::Server.new("http://#{host}:#{port}")
end
@@ -26,7 +27,7 @@ def delete_doc(id)
database.delete_doc(doc)
end
def delete_all_docs(view_name)
- all_docs = view_name.nil? ? all(:include_docs => true)["rows"] : MapReduce.map(view_name)
+ all_docs = view_name.nil? ? all : MapReduce.map(view_name)
all_docs.collect{|d| d["doc"]}.each do |doc|
database.delete_doc(doc) unless (doc["_id"] =~ /^_design/)
end
@@ -48,7 +49,7 @@ def get(id)
end
def all(options={})
- @db.documents(options)
+ @db.documents(options.merge(:include_docs => true))["rows"]
end
def debug=(value)
@debug = value

0 comments on commit fe7386f

Please sign in to comment.