added CouchRest::Model#attachment_url for someone to fetch the attachment using other means

This commit is contained in:
Jonathan S. Katz 2008-10-30 00:50:32 -04:00 committed by Chris Anderson
parent a79d9b7f90
commit 3bff23e7c5
2 changed files with 25 additions and 0 deletions

View file

@ -536,10 +536,17 @@ module CouchRest
self['_attachments'].delete attachment_name
end
# returns true if attachment_name exists
def has_attachment?(attachment_name)
!!(self['_attachments'] && self['_attachments'][attachment_name] && !self['_attachments'][attachment_name].empty?)
end
# returns URL to fetch the attachment from
def attachment_url(attachment_name)
return unless has_attachment?(attachment_name)
"#{database.root}/#{self.id}/#{attachment_name}"
end
protected
# Saves a document for the first time, after running the before(:create)