Module: Rid::Attachments

Included in:
Document
Defined in:
lib/rid/attachments.rb

Constant Summary collapse

MIME_TYPE_MAPPING =

Mime type mapping from extensions

{
  ".htm" => "text/html",
  ".html" => "text/html",
  ".js" => "text/javascript",
  ".css" => "text/css",
  ".manifest" => "text/cache-manifest",
  ".png" => "image/png",
  ".gif" => "image/gif",
  ".ico" => "image/x-icon",
}

Instance Method Summary collapse

Instance Method Details

#map_attachments!Object

encode attachments and add meta data



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rid/attachments.rb', line 18

def map_attachments!
  return if attachments.empty?

  doc = {}
  attachments.flatten.each do |key, value|
    doc[key] = {
      "data" => encode_attachment(value),
      "content_type" => mime_type_for(key)
    }
  end

  self.attachments = doc
end

#reduce_attachments!Object

decode attachments and flatten meta data hash



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rid/attachments.rb', line 34

def reduce_attachments!
  return if attachments.empty?

  doc = {}
  attachments.each do |key, value|
    data = value["data"]
    next unless data
    doc[key] = decode_attachment(data)
  end

  self.attachments = doc
end