Module: CouchRest::Mixins::ExtendedAttachments
- Included in:
- ExtendedDocument
- Defined in:
- lib/couchrest/mixins/extended_attachments.rb
Instance Method Summary (collapse)
-
- (Object) attachment_uri(attachment_name)
returns URI to fetch the attachment from.
-
- (Object) attachment_url(attachment_name)
returns URL to fetch the attachment from.
-
- (Object) create_attachment(args = {})
creates a file attachment to the current doc.
-
- (Object) delete_attachment(attachment_name)
deletes a file attachment from the current doc.
-
- (Boolean) has_attachment?(attachment_name)
returns true if attachment_name exists.
-
- (Object) read_attachment(attachment_name)
reads the data from an attachment.
-
- (Object) update_attachment(args = {})
modifies a file attachment on the current doc.
Instance Method Details
- (Object) attachment_uri(attachment_name)
returns URI to fetch the attachment from
48 49 50 51 |
# File 'lib/couchrest/mixins/extended_attachments.rb', line 48 def () return unless () "#{database.uri}/#{self.id}/#{}" end |
- (Object) attachment_url(attachment_name)
returns URL to fetch the attachment from
42 43 44 45 |
# File 'lib/couchrest/mixins/extended_attachments.rb', line 42 def () return unless () "#{database.root}/#{self.id}/#{}" end |
- (Object) create_attachment(args = {})
creates a file attachment to the current doc
6 7 8 9 10 11 12 13 |
# File 'lib/couchrest/mixins/extended_attachments.rb', line 6 def (args={}) raise ArgumentError unless args[:file] && args[:name] return if (args[:name]) self['_attachments'] ||= {} (args) rescue ArgumentError => e raise ArgumentError, 'You must specify :file and :name' end |
- (Object) delete_attachment(attachment_name)
deletes a file attachment from the current doc
31 32 33 34 |
# File 'lib/couchrest/mixins/extended_attachments.rb', line 31 def () return unless self['_attachments'] self['_attachments'].delete end |
- (Boolean) has_attachment?(attachment_name)
returns true if attachment_name exists
37 38 39 |
# File 'lib/couchrest/mixins/extended_attachments.rb', line 37 def () !!(self['_attachments'] && self['_attachments'][] && !self['_attachments'][].empty?) end |
- (Object) read_attachment(attachment_name)
reads the data from an attachment
16 17 18 |
# File 'lib/couchrest/mixins/extended_attachments.rb', line 16 def () database.(self, ) end |
- (Object) update_attachment(args = {})
modifies a file attachment on the current doc
21 22 23 24 25 26 27 28 |
# File 'lib/couchrest/mixins/extended_attachments.rb', line 21 def (args={}) raise ArgumentError unless args[:file] && args[:name] return unless (args[:name]) (args[:name]) (args) rescue ArgumentError => e raise ArgumentError, 'You must specify :file and :name' end |