Class: Valkyrie::Persistence::Fedora::OrderedReader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/valkyrie/persistence/fedora/ordered_reader.rb

Overview

Lazily iterates over a doubly linked list, fixing up nodes if necessary. Used for reading ordered members out of Fedora, and then converting them to member_ids.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ OrderedReader

Returns a new instance of OrderedReader.



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

def initialize(root)
  @root = root
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



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

def root
  @root
end

Instance Method Details

#eachObject



13
14
15
16
17
18
19
20
21
# File 'lib/valkyrie/persistence/fedora/ordered_reader.rb', line 13

def each
  proxy = first_head
  while proxy
    yield proxy unless proxy.nil?
    next_proxy = proxy.next
    next_proxy.try(:prev=, proxy) if next_proxy&.prev != proxy
    proxy = next_proxy
  end
end