Sha256: aab6f7b4b0def73f9a28fd8ca8fc295c0dccc14d01cd5ec4fa17c6f5a7e1f8e0

Contents?: true

Size: 1018 Bytes

Versions: 10

Compression:

Stored size: 1018 Bytes

Contents

module ActiveFedora::Aggregation
  class LinkInserter
    attr_reader :root, :proxy
    # @param [ProxyOwner] root the node representing the aggregation
    # @param [Proxy] proxy the proxy to add to the aggregation
    def initialize(root, proxy)
      @root = root
      @proxy = proxy
    end

    def call
      if root.head
        append
      else
        set
      end
      proxy.container = root
      persist_nodes!
    end

    private

    def append
      Appender.new(root, proxy).call
    end

    def set
      root.head = proxy
      root.tail = proxy
    end

    def persist_nodes!
      [proxy, proxy.prev].uniq.compact.each(&:save!)
    end

    class Appender
      attr_reader :root, :proxy
      def initialize(root, proxy)
        @root = root
        @proxy = proxy
      end

      def call
        last_proxy.next = proxy
        proxy.prev = last_proxy
        root.tail = proxy
      end

      private

      def last_proxy
        @last_proxy ||= root.tail
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
activefedora-aggregation-0.9.0 lib/active_fedora/aggregation/link_inserter.rb
activefedora-aggregation-0.8.1 lib/active_fedora/aggregation/link_inserter.rb
activefedora-aggregation-0.8.0 lib/active_fedora/aggregation/link_inserter.rb
activefedora-aggregation-0.7.0 lib/active_fedora/aggregation/link_inserter.rb
activefedora-aggregation-0.6.0 lib/active_fedora/aggregation/link_inserter.rb
activefedora-aggregation-0.5.0 lib/active_fedora/aggregation/link_inserter.rb
activefedora-aggregation-0.4.2 lib/active_fedora/aggregation/link_inserter.rb
activefedora-aggregation-0.4.1 lib/active_fedora/aggregation/link_inserter.rb
activefedora-aggregation-0.4.0 lib/active_fedora/aggregation/link_inserter.rb
activefedora-aggregation-0.3.0 lib/active_fedora/aggregation/link_inserter.rb