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.



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

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



34
35
36
# File 'lib/ldp/resource/rdf_source.rb', line 34

def build_empty_graph
  graph_class.new
end

#contentObject



26
27
28
# File 'lib/ldp/resource/rdf_source.rb', line 26

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

#createObject



20
21
22
23
24
# File 'lib/ldp/resource/rdf_source.rb', line 20

def create
  super do |req|
    req.headers["Content-Type"] = "text/turtle"
  end
end

#graphObject



30
31
32
# File 'lib/ldp/resource/rdf_source.rb', line 30

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

#graph_classObject

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



42
43
44
# File 'lib/ldp/resource/rdf_source.rb', line 42

def graph_class
  RDF::Graph
end