added an automated way to mark design docs as dirty after the db was reset
This commit is contained in:
parent
e48a6c8866
commit
c35c35157a
10 changed files with 41 additions and 25 deletions
|
@ -236,6 +236,16 @@ module CouchRest
|
|||
copy_doc(doc, dest)
|
||||
end
|
||||
|
||||
def extended_document_classes
|
||||
@extended_document_classes ||= []
|
||||
end
|
||||
|
||||
# store extended document classes so we can clear
|
||||
# their freshness when we reset the DB
|
||||
def register_extended_document_class(klass)
|
||||
extended_document_classes << klass
|
||||
end
|
||||
|
||||
# Compact the database, removing old document revisions and optimizing space use.
|
||||
def compact!
|
||||
CouchRest.post "#{@uri}/_compact"
|
||||
|
@ -271,11 +281,16 @@ module CouchRest
|
|||
# DELETE the database itself. This is not undoable and could be rather
|
||||
# catastrophic. Use with care!
|
||||
def delete!
|
||||
clear_extended_doc_fresh_cache
|
||||
CouchRest.delete @uri
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def clear_extended_doc_fresh_cache
|
||||
extended_document_classes.each{|klass| klass.design_doc_fresh = false if klass.respond_to?(:design_doc_fresh=) }
|
||||
end
|
||||
|
||||
def uri_for_attachment(doc, name)
|
||||
if doc.is_a?(String)
|
||||
puts "CouchRest::Database#fetch_attachment will eventually require a doc as the first argument, not a doc.id"
|
||||
|
|
|
@ -20,6 +20,15 @@ module CouchRest
|
|||
subklass.properties = self.properties.dup
|
||||
end
|
||||
EOS
|
||||
|
||||
# re opening the use_database method so we can register our class
|
||||
subklass.class_eval <<-EOS, __FILE__, __LINE__
|
||||
def self.use_database(db)
|
||||
super
|
||||
db.register_extended_document_class(self) if db.respond_to?(:register_extended_document_class) && !db.extended_document_classes.include?(self)
|
||||
end
|
||||
EOS
|
||||
|
||||
end
|
||||
|
||||
# Accessors
|
||||
|
@ -45,6 +54,8 @@ module CouchRest
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
# Automatically set <tt>updated_at</tt> and <tt>created_at</tt> fields
|
||||
# on the document whenever saving occurs. CouchRest uses a pretty
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue