Sha256: 0991c18ae46818584e19c689b384022389f02ae34a482fdfc710526d6d4197d8

Contents?: true

Size: 935 Bytes

Versions: 6

Compression:

Stored size: 935 Bytes

Contents

module Exegesis
  module Document
    class Attachment
      
      attr_reader :name, :metadata, :document
      
      def initialize(name, thing, doc)
        @document = doc
        @metadata = thing
        @name = name
      end
      
      def to_s
        "#<Exegesis::Document::Attachment document=#{@document.uri} #{@metadata.inspect}>"
      end
      alias :inspect :to_s
      
      def content_type
        @metadata['content_type']
      end
      
      def length
        @metadata['length'] || -1
      end
      
      def stub?
        @metadata['stub'] || false
      end
      
      def file
        RestClient.get("#{document.database.uri}/#{document.id}/#{name}")
      end
      
      def to_json
        if @metadata['data']
          {'content_type' => @metadata['content_type'], 'data' => @metadata['data']}.to_json
        else
          @metadata.to_json
        end
      end
      
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mattly-exegesis-0.2.1 lib/exegesis/document/attachment.rb
mattly-exegesis-0.2.2 lib/exegesis/document/attachment.rb
mattly-exegesis-0.2.3 lib/exegesis/document/attachment.rb
mattly-exegesis-0.2.5 lib/exegesis/document/attachment.rb
mattly-exegesis-0.2.6 lib/exegesis/document/attachment.rb
mattly-exegesis-0.2.8 lib/exegesis/document/attachment.rb