Sha256: 0f33e5b9767fa1bdcc748ea4f573358c852ef0e7798a3f4ab2febd37debf8635

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

module ActiveFedora
  module Orders
    class TargetProxy
      attr_reader :association
      delegate :+, to: :to_a
      def initialize(association)
        @association = association
      end

      def <<(obj)
        association.append_target(obj)
        self
      end

      def concat(objs)
        objs.each do |obj|
          self.<<(obj)
        end
        self
      end

      def insert_at(loc, record)
        association.insert_target_at(loc, record)
        self
      end

      def ids
        association.reader.map(&:target_id)
      end

      # Deletes the element at the specified index, returning that element, or nil if
      # the index is out of range.
      def delete_at(loc)
        result = association.delete_at(loc)
        result&.target
      end

      # Deletes all items from self that are equal to obj.
      # @param obj the object to remove from the list
      # @return the last deleted item, or nil if no matching item is found
      def delete(obj)
        association.delete_target(obj)
      end

      def clear
        association.delete_at(0) while to_ary.present?
      end

      def to_ary
        association.reader.map(&:target).dup
      end
      alias to_a to_ary

      def ==(other)
        case other
        when TargetProxy
          super
        when Array
          to_a == other
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active-fedora-15.0.1 lib/active_fedora/orders/target_proxy.rb
active-fedora-15.0.0 lib/active_fedora/orders/target_proxy.rb
active-fedora-14.0.1 lib/active_fedora/orders/target_proxy.rb
active-fedora-14.0.0 lib/active_fedora/orders/target_proxy.rb