Sha256: 699340b4f2c89aeb628ef53bf0a6c80d866210aa3853c078affc7f938c8f2a9a

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

      # 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)
        if result
          result.target
        end
      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
        while to_ary.present?
          association.delete_at(0)
        end
      end

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activefedora-aggregation-0.10.0 lib/active_fedora/orders/target_proxy.rb
activefedora-aggregation-0.9.0 lib/active_fedora/orders/target_proxy.rb
activefedora-aggregation-0.8.1 lib/active_fedora/orders/target_proxy.rb
activefedora-aggregation-0.8.0 lib/active_fedora/orders/target_proxy.rb