returns URI to fetch the attachment from
# File lib/couchrest/mixins/extended_attachments.rb, line 49 def attachment_uri(attachment_name) return unless has_attachment?(attachment_name) "#{database.uri}/#{self.id}/#{attachment_name}" end
returns URL to fetch the attachment from
# File lib/couchrest/mixins/extended_attachments.rb, line 43 def attachment_url(attachment_name) return unless has_attachment?(attachment_name) "#{database.root}/#{self.id}/#{attachment_name}" end
Add a file attachment to the current document. Expects :file and :name to be included in the arguments.
# File lib/couchrest/mixins/extended_attachments.rb, line 7 def create_attachment(args={}) raise ArgumentError unless args[:file] && args[:name] return if has_attachment?(args[:name]) self['_attachments'] ||= {} set_attachment_attr(args) rescue ArgumentError => e raise ArgumentError, 'You must specify :file and :name' end
deletes a file attachment from the current doc
# File lib/couchrest/mixins/extended_attachments.rb, line 32 def delete_attachment(attachment_name) return unless self['_attachments'] self['_attachments'].delete attachment_name end
returns true if attachment_name exists
# File lib/couchrest/mixins/extended_attachments.rb, line 38 def has_attachment?(attachment_name) !!(self['_attachments'] && self['_attachments'][attachment_name] && !self['_attachments'][attachment_name].empty?) end
reads the data from an attachment
# File lib/couchrest/mixins/extended_attachments.rb, line 17 def read_attachment(attachment_name) database.fetch_attachment(self, attachment_name) end
modifies a file attachment on the current doc
# File lib/couchrest/mixins/extended_attachments.rb, line 22 def update_attachment(args={}) raise ArgumentError unless args[:file] && args[:name] return unless has_attachment?(args[:name]) delete_attachment(args[:name]) set_attachment_attr(args) rescue ArgumentError => e raise ArgumentError, 'You must specify :file and :name' end