Sha256: 4697aca9b9cc34b6c858f70884b3e13b7cdbb5d80be7d1174fd21165dfe5bf95

Contents?: true

Size: 897 Bytes

Versions: 10

Compression:

Stored size: 897 Bytes

Contents

module Ldp
  class Resource::BinarySource < Ldp::Resource
    attr_accessor :content

    def initialize client, subject, content_or_response = nil, base_path = ''
      super

      case content_or_response
      when Faraday::Response
      else
        @content = content_or_response
      end
    end

    def content
      @content ||= get.body
    end

    def described_by
      described_by = Array(head.links["describedby"]).first

      client.find_or_initialize described_by if described_by
    end

    # Override inspect so that `content` is never shown. It is typically too big to be helpful
    def inspect
      string = "#<#{self.class.name}:#{self.object_id} "
      fields = [:subject].map{|field| "#{field}=\"#{self.send(field)}\""}
      string << fields.join(", ") << ">"
    end

    protected

    def interaction_model
      RDF::Vocab::LDP.NonRDFSource
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ldp-1.0.0 lib/ldp/resource/binary_source.rb
ldp-0.7.2 lib/ldp/resource/binary_source.rb
ldp-0.7.1 lib/ldp/resource/binary_source.rb
ldp-0.7.0 lib/ldp/resource/binary_source.rb
ldp-0.6.4 lib/ldp/resource/binary_source.rb
ldp-0.6.3 lib/ldp/resource/binary_source.rb
ldp-0.6.2 lib/ldp/resource/binary_source.rb
ldp-0.6.1 lib/ldp/resource/binary_source.rb
ldp-0.6.0 lib/ldp/resource/binary_source.rb
ldp-0.5.0 lib/ldp/resource/binary_source.rb