Class: Valkyrie::Persistence::Fedora::OrderedList
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Fedora::OrderedList
- Includes:
- Enumerable
- Defined in:
- lib/valkyrie/persistence/fedora/ordered_list.rb
Overview
Ruby object representation of an ORE doubly linked list. Used in the Fedora adapter for persisting ordered members.
Defined Under Namespace
Classes: HeadSentinel, NodeCache, Sentinel, TailSentinel
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#head ⇒ HeadSentinel
Sentinel for the top of the list.
-
#head_subject ⇒ Object
readonly
Returns the value of attribute head_subject.
-
#tail ⇒ TailSentinel
Sentinel for the bottom of the list.
-
#tail_subject ⇒ Object
readonly
Returns the value of attribute tail_subject.
Instance Method Summary collapse
-
#initialize(graph, head_subject, tail_subject, adapter) ⇒ OrderedList
constructor
A new instance of OrderedList.
- #insert_proxy_for_at(loc, proxy_for, proxy_in: nil) ⇒ Object
-
#to_graph ⇒ ::RDF::Graph
Graph representation of this list.
Constructor Details
#initialize(graph, head_subject, tail_subject, adapter) ⇒ OrderedList
Returns a new instance of OrderedList.
16 17 18 19 20 21 22 23 24 |
# File 'lib/valkyrie/persistence/fedora/ordered_list.rb', line 16 def initialize(graph, head_subject, tail_subject, adapter) @graph = graph @head_subject = head_subject @tail_subject = tail_subject @node_cache ||= NodeCache.new @adapter = adapter @changed = false tail end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/valkyrie/persistence/fedora/ordered_list.rb', line 7 def adapter @adapter end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
7 8 9 |
# File 'lib/valkyrie/persistence/fedora/ordered_list.rb', line 7 def graph @graph end |
#head ⇒ HeadSentinel
Returns Sentinel for the top of the list. If not empty, head.next is the first element.
28 29 30 |
# File 'lib/valkyrie/persistence/fedora/ordered_list.rb', line 28 def head @head ||= HeadSentinel.new(self, next_node: build_node(head_subject)) end |
#head_subject ⇒ Object (readonly)
Returns the value of attribute head_subject.
7 8 9 |
# File 'lib/valkyrie/persistence/fedora/ordered_list.rb', line 7 def head_subject @head_subject end |
#tail ⇒ TailSentinel
Returns Sentinel for the bottom of the list. If not empty, tail.prev is the first element.
34 35 36 37 38 39 40 41 |
# File 'lib/valkyrie/persistence/fedora/ordered_list.rb', line 34 def tail @tail ||= if tail_subject TailSentinel.new(self, prev_node: build_node(tail_subject)) else head.next end end |
#tail_subject ⇒ Object (readonly)
Returns the value of attribute tail_subject.
7 8 9 |
# File 'lib/valkyrie/persistence/fedora/ordered_list.rb', line 7 def tail_subject @tail_subject end |
Instance Method Details
#insert_proxy_for_at(loc, proxy_for, proxy_in: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/valkyrie/persistence/fedora/ordered_list.rb', line 45 def insert_proxy_for_at(loc, proxy_for, proxy_in: nil) node = build_node(new_node_subject) node.proxy_for = proxy_for node.proxy_in = proxy_in if loc.zero? append_to(node, head) else append_to(node, ordered_reader.take(loc).last) end end |
#to_graph ⇒ ::RDF::Graph
Returns Graph representation of this list.
57 58 59 60 61 62 63 64 |
# File 'lib/valkyrie/persistence/fedora/ordered_list.rb', line 57 def to_graph ::RDF::Graph.new.tap do |g| array = to_a array.map(&:to_graph).each do |resource_graph| g << resource_graph end end end |