Class: Exegesis::Document::Attachments
- Inherits:
-
Hash
- Object
- Hash
- Exegesis::Document::Attachments
- Defined in:
- lib/exegesis/document/attachments.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
Instance Method Summary collapse
- #[]=(name, contents_and_type) ⇒ Object
- #clean! ⇒ Object
- #dirty? ⇒ Boolean
-
#initialize(doc) ⇒ Attachments
constructor
A new instance of Attachments.
-
#put(name, contents, type) ⇒ Object
saves the attachment to the database NOW.
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(doc) ⇒ Attachments
Returns a new instance of Attachments.
8 9 10 11 12 13 14 15 |
# File 'lib/exegesis/document/attachments.rb', line 8 def initialize doc @document = doc if @document['_attachments'] @document['_attachments'].each do |name,| update(name => Exegesis::Document::Attachment.new(name, , document)) end end end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
6 7 8 |
# File 'lib/exegesis/document/attachments.rb', line 6 def document @document end |
Instance Method Details
#[]=(name, contents_and_type) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/exegesis/document/attachments.rb', line 44 def []= name, contents_and_type @dirty = true content = contents_and_type.shift = {'data' => Base64.encode64(content).gsub(/\s/,''), 'content_type' => contents_and_type.first, 'length' => content.length} update(name => Exegesis::Document::Attachment.new(name, , document)) end |
#clean! ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/exegesis/document/attachments.rb', line 26 def clean! each do |name, | next if .stub? .['stub'] = true ..delete('data') end @dirty = false end |
#dirty? ⇒ Boolean
22 23 24 |
# File 'lib/exegesis/document/attachments.rb', line 22 def dirty? @dirty || false end |
#put(name, contents, type) ⇒ Object
saves the attachment to the database NOW. does not keep the attachment in memory once this is done.
36 37 38 39 40 41 42 |
# File 'lib/exegesis/document/attachments.rb', line 36 def put(name, contents, type) r = Exegesis::Http.put("#{document.uri}/#{name}?rev=#{document.rev}", contents, {:content_type => type}) if r['ok'] document['_rev'] = r['rev'] update(name => Exegesis::Document::Attachment.new(name, {'content_type' => type, 'stub' => true, 'length' => contents.length}, document)) end end |
#to_s ⇒ Object Also known as: inspect
17 18 19 |
# File 'lib/exegesis/document/attachments.rb', line 17 def to_s "#<Exegesis::Document::Attachments document=#{@document.uri} attachments=#{keys.join(', ')}>" end |