Class: Valkyrie::Persistence::Fedora::OrderedList

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(graph, head_subject, tail_subject, adapter) ⇒ OrderedList

Returns a new instance of OrderedList.

Parameters:

  • graph (::RDF::Enumerable)

    Enumerable where ORE statements are stored.

  • head_subject (::RDF::URI)

    URI of head node in list.

  • tail_subject (::RDF::URI)

    URI of tail node in list.



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

#adapterObject (readonly)

Returns the value of attribute adapter.



7
8
9
# File 'lib/valkyrie/persistence/fedora/ordered_list.rb', line 7

def adapter
  @adapter
end

#graphObject (readonly)

Returns the value of attribute graph.



7
8
9
# File 'lib/valkyrie/persistence/fedora/ordered_list.rb', line 7

def graph
  @graph
end

#headHeadSentinel

Returns Sentinel for the top of the list. If not empty, head.next is the first element.

Returns:

  • (HeadSentinel)

    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_subjectObject (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

#tailTailSentinel

Returns Sentinel for the bottom of the list. If not empty, tail.prev is the first element.

Returns:

  • (TailSentinel)

    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_subjectObject (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

Parameters:

  • loc (Integer)

    Location to insert target at

  • proxy_for (String)

    proxyFor to add



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.

Returns:

  • (::RDF::Graph)

    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