Module: CouchRest::Model::ExtendedAttachments
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/couchrest/model/extended_attachments.rb
Instance Method Summary collapse
-
#attachment_uri(attachment_name) ⇒ Object
returns URI to fetch the attachment from.
-
#attachment_url(attachment_name) ⇒ Object
returns URL to fetch the attachment from.
-
#attachments ⇒ Object
return all attachments.
-
#create_attachment(args = {}) ⇒ Object
Add a file attachment to the current document.
-
#delete_attachment(attachment_name) ⇒ Object
deletes a file attachment from the current doc.
-
#has_attachment?(attachment_name) ⇒ Boolean
returns true if attachment_name exists.
-
#read_attachment(attachment_name) ⇒ Object
reads the data from an attachment.
-
#update_attachment(args = {}) ⇒ Object
modifies a file attachment on the current doc.
Instance Method Details
#attachment_uri(attachment_name) ⇒ Object
returns URI to fetch the attachment from
57 58 59 60 |
# File 'lib/couchrest/model/extended_attachments.rb', line 57 def () return unless () "#{database.uri}/#{self.id}/#{}" end |
#attachment_url(attachment_name) ⇒ Object
returns URL to fetch the attachment from
51 52 53 54 |
# File 'lib/couchrest/model/extended_attachments.rb', line 51 def () return unless () "#{database.root}/#{self.id}/#{}" end |
#attachments ⇒ Object
return all attachments
17 18 19 |
# File 'lib/couchrest/model/extended_attachments.rb', line 17 def self['_attachments'] ||= {} end |
#create_attachment(args = {}) ⇒ Object
Add a file attachment to the current document. Expects :file and :name to be included in the arguments.
8 9 10 11 12 13 14 |
# File 'lib/couchrest/model/extended_attachments.rb', line 8 def (args={}) raise ArgumentError unless args[:file] && args[:name] return if (args[:name]) (args) rescue ArgumentError => e raise ArgumentError, 'You must specify :file and :name' end |
#delete_attachment(attachment_name) ⇒ Object
deletes a file attachment from the current doc
37 38 39 40 41 42 43 |
# File 'lib/couchrest/model/extended_attachments.rb', line 37 def () return unless if .include?() attribute_will_change!("_attachments") .delete end end |
#has_attachment?(attachment_name) ⇒ Boolean
returns true if attachment_name exists
46 47 48 |
# File 'lib/couchrest/model/extended_attachments.rb', line 46 def () !!( && [] && ![].empty?) end |
#read_attachment(attachment_name) ⇒ Object
reads the data from an attachment
22 23 24 |
# File 'lib/couchrest/model/extended_attachments.rb', line 22 def () database.(self, ) end |
#update_attachment(args = {}) ⇒ Object
modifies a file attachment on the current doc
27 28 29 30 31 32 33 34 |
# File 'lib/couchrest/model/extended_attachments.rb', line 27 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 |