lib/ruote/couch/database.rb in ruote-couch-2.1.8 vs lib/ruote/couch/database.rb in ruote-couch-2.1.9
- old
+ new
@@ -103,31 +103,31 @@
s2 << " #{k} => #{e[k].inspect}\n"
end
end
end
- def shutdown
+ #def shutdown
+ # @couch.close
+ #end
+ # jig > 0.1.17 is OK without that
- @couch.close
- end
-
- # Deletes database and closes it.
+ # Deletes all the documents in this database.
#
def purge!
- @couch.delete('.')
- @couch.close
+ @couch.get('_all_docs')['rows'].each do |row|
+ doc = { '_id' => row['id'], '_rev' => row['value']['rev'] }
+ @couch.delete(doc) unless doc['_id'].match(/^\_design\//)
+ end
+ #
+ # which is faster than
+ #
+ #@couch.delete('.')
+ #@couch.put('.')
+ #@couch.http.cache.clear
end
- # Removes all the documents in this database.
- #
- def purge_docs!
-
- @couch.delete('.')
- @couch.put('.')
- end
-
protected
def prepare
# nothing to do for a index-less database
@@ -187,10 +187,17 @@
def by_wfid (wfid)
get_many(/!#{wfid}$/, {})
end
+ # Returns the design document that goes with this class of database
+ #
+ def self.design_doc
+
+ self.allocate.send(:design_doc)
+ end
+
protected
def design_doc
{
@@ -205,11 +212,16 @@
end
def prepare
d = @couch.get('_design/ruote')
- @couch.delete(d) if d
+
+ return if d && d['views'] == design_doc['views']
+
+ d ||= design_doc
+ d['views'] = design_doc['views']
+
@couch.put(design_doc)
end
end
#
@@ -270,9 +282,16 @@
hwis = hwis.select { |hwi|
Ruote::StorageParticipant.matches?(hwi, pname, criteria) }
hwis.collect { |hwi| Ruote::Workitem.new(hwi) }
+ end
+
+ # Returns the design document that goes with this class of database
+ #
+ def self.design_doc
+
+ self.allocate.send(:design_doc)
end
protected
def design_doc