Sha256: 9be5913646cac799c6b8a1a93327db0afc32c340204f7ccc44446b9cda75d9fd

Contents?: true

Size: 575 Bytes

Versions: 7

Compression:

Stored size: 575 Bytes

Contents

module ActiveFedora::Aggregation
  ##
  # Lazily iterates over a doubly linked list, fixing up nodes if necessary.
  class OrderedReader
    include Enumerable
    attr_reader :root
    def initialize(root)
      @root = root
    end

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

    private

    def first_head
      root.head
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
activefedora-aggregation-0.10.0 lib/active_fedora/aggregation/ordered_reader.rb
activefedora-aggregation-0.9.0 lib/active_fedora/aggregation/ordered_reader.rb
activefedora-aggregation-0.8.1 lib/active_fedora/aggregation/ordered_reader.rb
activefedora-aggregation-0.8.0 lib/active_fedora/aggregation/ordered_reader.rb
activefedora-aggregation-0.7.0 lib/active_fedora/aggregation/ordered_reader.rb
activefedora-aggregation-0.6.0 lib/active_fedora/aggregation/ordered_reader.rb
activefedora-aggregation-0.5.0 lib/active_fedora/aggregation/ordered_reader.rb