Sha256: da7ee8da305eefe7a77d2e7c0b7b61767664943d47c6f3c315888f06d706d424

Contents?: true

Size: 1.3 KB

Versions: 15

Compression:

Stored size: 1.3 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)
        result.target if result
      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

15 entries across 15 versions & 1 rubygems

Version Path
active-fedora-10.3.0 lib/active_fedora/orders/target_proxy.rb
active-fedora-10.3.0.rc2 lib/active_fedora/orders/target_proxy.rb
active-fedora-10.3.0.rc1 lib/active_fedora/orders/target_proxy.rb
active-fedora-10.2.1 lib/active_fedora/orders/target_proxy.rb
active-fedora-10.2.0 lib/active_fedora/orders/target_proxy.rb
active-fedora-10.1.0 lib/active_fedora/orders/target_proxy.rb
active-fedora-10.1.0.rc1 lib/active_fedora/orders/target_proxy.rb
active-fedora-10.0.0 lib/active_fedora/orders/target_proxy.rb
active-fedora-10.0.0.beta4 lib/active_fedora/orders/target_proxy.rb
active-fedora-10.0.0.beta3 lib/active_fedora/orders/target_proxy.rb
active-fedora-10.0.0.beta2 lib/active_fedora/orders/target_proxy.rb
active-fedora-10.0.0.beta1 lib/active_fedora/orders/target_proxy.rb
active-fedora-9.13.0 lib/active_fedora/orders/target_proxy.rb
active-fedora-9.12.0 lib/active_fedora/orders/target_proxy.rb
active-fedora-9.11.0 lib/active_fedora/orders/target_proxy.rb