Module: CouchRest::Mixins::Attachments

Included in:
Document
Defined in:
lib/couchrest/mixins/attachments.rb

Instance Method Summary collapse

Instance Method Details

#delete_attachment(name, force = false) ⇒ Object

deletes an attachment directly from couchdb

Raises:

  • (ArgumentError)


22
23
24
25
26
27
# File 'lib/couchrest/mixins/attachments.rb', line 22

def delete_attachment(name, force=false)
  raise ArgumentError, "doc.database required to delete_attachment" unless database
  result = database.delete_attachment(self, name, force)
  self['_rev'] = result['rev']
  result['ok']
end

#fetch_attachment(name) ⇒ Object

returns an attachment’s data

Raises:

  • (ArgumentError)


15
16
17
18
19
# File 'lib/couchrest/mixins/attachments.rb', line 15

def fetch_attachment(name)
  raise ArgumentError, "doc must be saved" unless self.rev
  raise ArgumentError, "doc.database required to put_attachment" unless database
  database.fetch_attachment(self, name)
end

#put_attachment(name, file, options = {}) ⇒ Object

saves an attachment directly to couchdb

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
# File 'lib/couchrest/mixins/attachments.rb', line 6

def put_attachment(name, file, options={})
  raise ArgumentError, "doc must be saved" unless self.rev
  raise ArgumentError, "doc.database required to put_attachment" unless database
  result = database.put_attachment(self, name, file, options)
  self['_rev'] = result['rev']
  result['ok']
end