Class: Ldp::Resource::RdfSource
- Inherits:
-
Ldp::Resource
- Object
- Ldp::Resource
- Ldp::Resource::RdfSource
- Defined in:
- lib/ldp/resource/rdf_source.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Ldp::Resource
Instance Method Summary collapse
- #build_empty_graph ⇒ Object
- #content ⇒ Object
- #create ⇒ Object
- #graph ⇒ Object
-
#graph_class ⇒ Class
graph_class may be overridden so that a subclass of RDF::Graph is returned (e.g. an ActiveTriples resource).
-
#initialize(client, subject, graph_or_response = nil, base_path = '') ⇒ RdfSource
constructor
A new instance of RdfSource.
-
#response_graph ⇒ RDF::Graph
Parse the graph returned by the LDP server into an RDF::Graph.
Methods inherited from Ldp::Resource
#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
Returns a new instance of RdfSource.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 # no-op nil when NilClass # no-op nil 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
45 46 47 |
# File 'lib/ldp/resource/rdf_source.rb', line 45 def build_empty_graph graph_class.new end |
#content ⇒ Object
27 28 29 |
# File 'lib/ldp/resource/rdf_source.rb', line 27 def content graph.dump(:ttl) if graph end |
#create ⇒ Object
21 22 23 24 25 |
# File 'lib/ldp/resource/rdf_source.rb', line 21 def create super do |req| req.headers["Content-Type"] = "text/turtle" end end |
#graph ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ldp/resource/rdf_source.rb', line 31 def graph @graph ||= begin if subject.nil? build_empty_graph else filtered_graph(response_graph) end rescue Ldp::NotFound # This is an optimization that lets us avoid doing HEAD + GET # when the object exists. We just need to handle the 404 case 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)
53 54 55 |
# File 'lib/ldp/resource/rdf_source.rb', line 53 def graph_class RDF::Graph end |
#response_graph ⇒ RDF::Graph
Parse the graph returned by the LDP server into an RDF::Graph
60 61 62 |
# File 'lib/ldp/resource/rdf_source.rb', line 60 def response_graph @response_graph ||= response_as_graph(get) end |