Class: Valkyrie::Persistence::Fedora::ListNode
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Fedora::ListNode
- Defined in:
- lib/valkyrie/persistence/fedora/list_node.rb
Overview
Represents a node in an ORE List. Used for persisting ordered members into an Resource Description Framework (RDF) Graph for Fedora, to keep order maintained.
RDF graph nodes are used to implement a linked list An RDF hash URI is referenced for the list itself <www.iana.org/assignments/relation/first> is the predicate which links to the first element in the list <www.iana.org/assignments/relation/last> is the predicate which links to the last element Each element is also referenced using a hash URI <www.iana.org/assignments/relation/next> is the predicate which links one element to the next element in the list (This permits unidirectional traversal) <www.openarchives.org/ore/terms/proxyFor> is the predicate which links any given element to its value (These can be IRIs or XML literals supported by a graph store)
Defined Under Namespace
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#next ⇒ RDF::URI
Returns the next proxy or a tail sentinel.
-
#next_uri ⇒ Object
writeonly
Sets the attribute next_uri.
-
#prev ⇒ RDF::URI
Returns the previous proxy or a head sentinel.
-
#prev_uri ⇒ Object
writeonly
Sets the attribute prev_uri.
-
#proxy_for ⇒ Object
Returns the value of attribute proxy_for.
-
#proxy_in ⇒ Object
Returns the value of attribute proxy_in.
-
#rdf_subject ⇒ Object
readonly
Returns the value of attribute rdf_subject.
Instance Method Summary collapse
-
#initialize(node_cache, rdf_subject, adapter, graph = RDF::Repository.new) ⇒ ListNode
constructor
A new instance of ListNode.
-
#target ⇒ RDF::URI
Or [String].
- #target_id ⇒ String
-
#to_graph ⇒ Valkyrie::Persistence::Fedora::ListNode::Resource
Graph representation of node.
Constructor Details
#initialize(node_cache, rdf_subject, adapter, graph = RDF::Repository.new) ⇒ ListNode
Returns a new instance of ListNode.
29 30 31 32 33 34 35 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 29 def initialize(node_cache, rdf_subject, adapter, graph = RDF::Repository.new) @rdf_subject = rdf_subject @graph = graph @node_cache = node_cache @adapter = adapter Builder.new(rdf_subject, graph).populate(self) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
23 24 25 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 23 def adapter @adapter end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
19 20 21 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 19 def graph @graph end |
#next ⇒ RDF::URI
Returns the next proxy or a tail sentinel.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 39 def next @next ||= if next_uri node_cache.fetch(next_uri) do node = self.class.new(node_cache, next_uri, adapter, graph) node.prev = self node end end end |
#next_uri=(value) ⇒ Object
Sets the attribute next_uri
21 22 23 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 21 def next_uri=(value) @next_uri = value end |
#prev ⇒ RDF::URI
Returns the previous proxy or a head sentinel.
52 53 54 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 52 def prev @prev ||= node_cache.fetch(prev_uri) if prev_uri end |
#prev_uri=(value) ⇒ Object
Sets the attribute prev_uri
21 22 23 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 21 def prev_uri=(value) @prev_uri = value end |
#proxy_for ⇒ Object
Returns the value of attribute proxy_for.
22 23 24 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 22 def proxy_for @proxy_for end |
#proxy_in ⇒ Object
Returns the value of attribute proxy_in.
22 23 24 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 22 def proxy_in @proxy_in end |
#rdf_subject ⇒ Object (readonly)
Returns the value of attribute rdf_subject.
19 20 21 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 19 def rdf_subject @rdf_subject end |
Instance Method Details
#target ⇒ RDF::URI
Returns or [String].
69 70 71 72 73 74 75 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 69 def target if target_id.is_a?(Valkyrie::ID) adapter.id_to_uri(target_id.to_s) else target_id end end |
#target_id ⇒ String
78 79 80 81 82 83 84 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 78 def target_id if proxy_for.to_s.include?("/") && proxy_for.to_s.start_with?(adapter.connection_prefix) adapter.uri_to_id(proxy_for) else proxy_for end end |
#to_graph ⇒ Valkyrie::Persistence::Fedora::ListNode::Resource
Graph representation of node.
58 59 60 61 62 63 64 65 66 |
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 58 def to_graph return RDF::Graph.new if target_id.blank? g = Resource.new(rdf_subject) g.proxy_for = target g.proxy_in = proxy_in.try(:uri) g.next = self.next.try(:rdf_subject) g.prev = prev.try(:rdf_subject) g.graph end |