Class: Valkyrie::Persistence::Fedora::ListNode

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/persistence/fedora/list_node.rb

Overview

Represents a node in an ORE List. Used for persisting ordered members into an RDF Graph for Fedora, to keep order maintained.

Defined Under Namespace

Classes: Builder, Resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_cache, rdf_subject, adapter, graph = RDF::Repository.new) ⇒ ListNode

Returns a new instance of ListNode.



12
13
14
15
16
17
18
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 12

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

#adapterObject (readonly)

Returns the value of attribute adapter.



11
12
13
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 11

def adapter
  @adapter
end

#graphObject (readonly)

Returns the value of attribute graph.



6
7
8
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 6

def graph
  @graph
end

#nextActiveFedora::Orders::ListNode

Returns the next proxy or a tail sentinel.

Returns:

  • (ActiveFedora::Orders::ListNode)


22
23
24
25
26
27
28
29
30
31
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 22

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

Parameters:

  • value

    the value to set the attribute next_uri to.



9
10
11
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 9

def next_uri=(value)
  @next_uri = value
end

#prevActiveFedora::Orders::ListNode

Returns the previous proxy or a head sentinel.

Returns:

  • (ActiveFedora::Orders::ListNode)


35
36
37
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 35

def prev
  @prev ||= node_cache.fetch(prev_uri) if prev_uri
end

#prev_uri=(value) ⇒ Object

Sets the attribute prev_uri

Parameters:

  • value

    the value to set the attribute prev_uri to.



9
10
11
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 9

def prev_uri=(value)
  @prev_uri = value
end

#proxy_forObject

Returns the value of attribute proxy_for.



10
11
12
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 10

def proxy_for
  @proxy_for
end

#proxy_inObject

Returns the value of attribute proxy_in.



10
11
12
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 10

def proxy_in
  @proxy_in
end

#rdf_subjectObject (readonly)

Returns the value of attribute rdf_subject.



6
7
8
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 6

def rdf_subject
  @rdf_subject
end

#targetObject

Returns the value of attribute target.



8
9
10
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 8

def target
  @target
end

Instance Method Details

#target_idObject



55
56
57
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 55

def target_id
  adapter.uri_to_id(proxy_for)
end

#target_uriObject



51
52
53
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 51

def target_uri
  adapter.id_to_uri(target_id.to_s)
end

#to_graphActiveFedora::Orders::ListNode::Resource

Graph representation of node.

Returns:

  • (ActiveFedora::Orders::ListNode::Resource)


41
42
43
44
45
46
47
48
49
# File 'lib/valkyrie/persistence/fedora/list_node.rb', line 41

def to_graph
  return RDF::Graph.new if target_id.blank?
  g = Resource.new(rdf_subject)
  g.proxy_for = target_uri
  g.proxy_in = proxy_in.try(:uri)
  g.next = self.next.try(:rdf_subject)
  g.prev = prev.try(:rdf_subject)
  g
end