Class: ActiveFedora::Orders::ListNode

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fedora/orders/list_node.rb

Defined Under Namespace

Classes: Builder, MaybeID, Resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ListNode.



6
7
8
9
10
11
# File 'lib/active_fedora/orders/list_node.rb', line 6

def initialize(node_cache, rdf_subject, graph = RDF::Repository.new)
  @rdf_subject = rdf_subject
  @graph = graph
  @node_cache = node_cache
  Builder.new(rdf_subject, graph).populate(self)
end

Instance Attribute Details

#nextActiveFedora::Orders::ListNode

Returns the next proxy or a tail sentinel.



15
16
17
18
19
20
21
22
23
24
# File 'lib/active_fedora/orders/list_node.rb', line 15

def next
  @next ||=
    if next_uri
      node_cache.fetch(next_uri) do
        node = self.class.new(node_cache, next_uri, 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.



4
5
6
# File 'lib/active_fedora/orders/list_node.rb', line 4

def next_uri=(value)
  @next_uri = value
end

#prevActiveFedora::Orders::ListNode

Returns the previous proxy or a head sentinel.



28
29
30
31
32
33
34
35
36
37
# File 'lib/active_fedora/orders/list_node.rb', line 28

def prev
  @prev ||=
    if prev_uri
      node_cache.fetch(prev_uri) do
        node = self.class.new(node_cache, prev_uri, graph)
        node.next = self
        node
      end
    end
end

#prev_uri=(value) ⇒ Object

Sets the attribute prev_uri

Parameters:

  • value

    the value to set the attribute prev_uri to.



4
5
6
# File 'lib/active_fedora/orders/list_node.rb', line 4

def prev_uri=(value)
  @prev_uri = value
end

#proxy_forObject

Returns the value of attribute proxy_for.



5
6
7
# File 'lib/active_fedora/orders/list_node.rb', line 5

def proxy_for
  @proxy_for
end

#proxy_inObject

Returns the value of attribute proxy_in.



5
6
7
# File 'lib/active_fedora/orders/list_node.rb', line 5

def proxy_in
  @proxy_in
end

#rdf_subjectObject (readonly)

Returns the value of attribute rdf_subject.



3
4
5
# File 'lib/active_fedora/orders/list_node.rb', line 3

def rdf_subject
  @rdf_subject
end

#targetActiveFedora::Base

Object representation of proxyFor

Returns:



52
53
54
55
56
57
58
59
# File 'lib/active_fedora/orders/list_node.rb', line 52

def target
  @target ||=
    if proxy_for.present?
      node_cache.fetch(proxy_for) do
        ActiveFedora::Base.from_uri(proxy_for, nil)
      end
    end
end

Instance Method Details

#changed_for_autosave?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/active_fedora/orders/list_node.rb', line 117

def changed_for_autosave?
  true
end

#destroyed?Boolean

Methods necessary for association functionality

Returns:

  • (Boolean)


105
106
107
# File 'lib/active_fedora/orders/list_node.rb', line 105

def destroyed?
  false
end

#marked_for_destruction?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/active_fedora/orders/list_node.rb', line 109

def marked_for_destruction?
  false
end

#new_record?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/active_fedora/orders/list_node.rb', line 121

def new_record?
  @target&.new_record?
end

#proxy_in_idObject



78
79
80
# File 'lib/active_fedora/orders/list_node.rb', line 78

def proxy_in_id
  MaybeID.new(@proxy_in.try(:id) || proxy_in).value
end

#save_targetObject

Persists target if it’s been accessed or set.



70
71
72
73
74
75
76
# File 'lib/active_fedora/orders/list_node.rb', line 70

def save_target
  if @target
    @target.save
  else
    true
  end
end

#target_idObject



65
66
67
# File 'lib/active_fedora/orders/list_node.rb', line 65

def target_id
  MaybeID.new(@target.try(:id) || proxy_for).value
end

#target_uriObject



61
62
63
# File 'lib/active_fedora/orders/list_node.rb', line 61

def target_uri
  RDF::URI(ActiveFedora::Base.id_to_uri(target_id)) if target_id
end

#to_graphActiveFedora::Orders::ListNode::Resource

Graph representation of node.



41
42
43
44
45
46
47
48
# File 'lib/active_fedora/orders/list_node.rb', line 41

def to_graph
  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

#valid?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/active_fedora/orders/list_node.rb', line 113

def valid?
  true
end