Sha256: 29ea20c9946cb8d6d5cb19ba78af4fe167a989aa1dbfdd0182ccf202f5241f8a

Contents?: true

Size: 1015 Bytes

Versions: 2

Compression:

Stored size: 1015 Bytes

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 delete_at(loc)
        result = association.delete_at(loc)
        if result
          result.target
        end
      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

2 entries across 2 versions & 1 rubygems

Version Path
activefedora-aggregation-0.7.0 lib/active_fedora/orders/target_proxy.rb
activefedora-aggregation-0.6.0 lib/active_fedora/orders/target_proxy.rb