Class: Ldp::Resource::RdfSource

Inherits:
Ldp::Resource show all
Defined in:
lib/ldp/resource/rdf_source.rb

Direct Known Subclasses

Container

Instance Attribute Summary

Attributes inherited from Ldp::Resource

#client, #subject

Instance Method Summary collapse

Methods inherited from Ldp::Resource

#current?, #delete, #get, #head, #new?, #reload, #retrieved_content?, #save, #subject_uri, #update, #update_cached_get

Constructor Details

#initialize(client, subject, graph_or_response = nil, base_path = '') ⇒ RdfSource

Returns a new instance of RdfSource.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ldp/resource/rdf_source.rb', line 4

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

  case graph_or_response
    when RDF::Graph
      @graph = graph_or_response
    when Ldp::Response
    when NilClass
      #nop
    else
      raise ArgumentError, "Third argument to #{self.class}.new should be a RDF::Graph or a Ldp::Response. You provided #{graph_or_response.class}"
  end
end

Instance Method Details

#build_empty_graphObject



32
33
34
# File 'lib/ldp/resource/rdf_source.rb', line 32

def build_empty_graph
  graph_class.new
end

#contentObject



24
25
26
# File 'lib/ldp/resource/rdf_source.rb', line 24

def content
  graph.dump(:ttl) if graph
end

#createObject



18
19
20
21
22
# File 'lib/ldp/resource/rdf_source.rb', line 18

def create
  super do |req|
    req.headers = { "Content-Type" => "text/turtle" }
  end
end

#graphObject



28
29
30
# File 'lib/ldp/resource/rdf_source.rb', line 28

def graph
  @graph ||= new? ? build_empty_graph : build_graph(get.graph)
end

#graph_classObject

graph_class may be overridden so that a subclass of RDF::Graph is returned (e.g. an ActiveTriples resource)



40
41
42
# File 'lib/ldp/resource/rdf_source.rb', line 40

def graph_class
  RDF::Graph
end