Class: Ldp::Resource::RdfSource
Instance Attribute Summary
#client, #subject
Instance Method Summary
collapse
#current?, #delete, for, #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
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::Enumerable
@graph = graph_or_response
when Ldp::Response
when NilClass
else
raise ArgumentError, "Third argument to #{self.class}.new should be a RDF::Enumerable or a Ldp::Response. You provided #{graph_or_response.class}"
end
end
|
Instance Method Details
#build_empty_graph ⇒ Object
42
43
44
|
# File 'lib/ldp/resource/rdf_source.rb', line 42
def build_empty_graph
graph_class.new
end
|
#content ⇒ Object
24
25
26
|
# File 'lib/ldp/resource/rdf_source.rb', line 24
def content
graph.dump(:ttl) if graph
end
|
#create ⇒ Object
18
19
20
21
22
|
# File 'lib/ldp/resource/rdf_source.rb', line 18
def create
super do |req|
req.["Content-Type"] = "text/turtle"
end
end
|
#graph ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/ldp/resource/rdf_source.rb', line 28
def graph
@graph ||= begin
if subject.nil?
build_empty_graph
else
filtered_graph(response_graph)
end
rescue Ldp::NotFound
build_empty_graph
end
end
|
#graph_class ⇒ Class
graph_class may be overridden so that a subclass of RDF::Graph is returned (e.g. an ActiveTriples resource)
50
51
52
|
# File 'lib/ldp/resource/rdf_source.rb', line 50
def graph_class
RDF::Graph
end
|
#response_graph ⇒ RDF::Graph
Parse the graph returned by the LDP server into an RDF::Graph
57
58
59
|
# File 'lib/ldp/resource/rdf_source.rb', line 57
def response_graph
@response_graph ||= response_as_graph(get)
end
|