Class: ActiveFedora::Aggregation::OrderedReader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_fedora/aggregation/ordered_reader.rb

Overview

Lazily iterates over a doubly linked list, fixing up nodes if necessary.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ OrderedReader

Returns a new instance of OrderedReader.



7
8
9
# File 'lib/active_fedora/aggregation/ordered_reader.rb', line 7

def initialize(root)
  @root = root
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



6
7
8
# File 'lib/active_fedora/aggregation/ordered_reader.rb', line 6

def root
  @root
end

Instance Method Details

#eachObject



11
12
13
14
15
16
17
18
19
# File 'lib/active_fedora/aggregation/ordered_reader.rb', line 11

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