Sha256: 8ab45cc7ddf9baa4a141a11bbd61fe6e06b0dfe9b6cbe55491adae64d4b75217

Contents?: true

Size: 897 Bytes

Versions: 8

Compression:

Stored size: 897 Bytes

Contents

require 'base64'

module Dolly
  module Attachment
    def attach_file! file_name, mime_type, body, opts={}
      attach_file file_name, mime_type, body, opts
      save
    end

    def attach_file file_name, mime_type, body, opts={}
      if opts[:inline]
        attach_inline_file file_name, mime_type, body
      else
        attach_standalone_file file_name, mime_type, body
      end
    end

    def attach_inline_file file_name, mime_type, body
      attachment_data = { file_name.to_s => { 'content_type' => mime_type,
                                              'data'         => Base64.encode64(body)} }
      doc['_attachments'] ||= {}
      doc['_attachments'].merge! attachment_data
    end

    def attach_standalone_file file_name, mime_type, body
      self.class.connection.attach id_as_resource, CGI.escape(file_name), body, { 'Content-Type' => mime_type }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dolly-3.1.5 lib/dolly/attachment.rb
dolly-3.1.4 lib/dolly/attachment.rb
dolly-3.1.3 lib/dolly/attachment.rb
dolly-3.1.2 lib/dolly/attachment.rb
dolly-3.1.1 lib/dolly/attachment.rb
dolly-3.1.0 lib/dolly/attachment.rb
dolly-3.0.1 lib/dolly/attachment.rb
dolly-3.0.0 lib/dolly/attachment.rb