Sha256: 0d81cbf6f7ba1415670e927935e874f9c21efaa97092e412249b7817ae552d9b

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module ActiveFedora::Aggregation
  class Association

    # @param [ActiveFedora::Base] parent
    # @param [Reflection] reflection
    # @opts options [String] class_name name of the class in the association
    def initialize(parent, reflection)
      @parent = parent
      @reflection = reflection
    end

    def klass
      @reflection.klass
    end

    def == other
      container.to_a == other
    end

    def create(&block)
      klass.create(&block).tap do |created|
        container << created
      end
      save #causes the (head/tail) pointers on the aggregation to be persisted
    end

    def save
      container.save
    end

    def target=(vals)
      container.target=(vals)
    end

    def target_ids=(vals)
      container.target_ids=(vals)
    end

    def target_ids
      container.target_ids
    end

    def container
      @container ||= begin
         ProxyContainer.find_or_initialize(klass.uri_to_id(uri)).tap do |container|
           container.parent = @parent
         end
      end
    end

    def first
      container.first
    end

    def uri
      @parent.uri + '/files'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activefedora-aggregation-0.2.1 lib/active_fedora/aggregation/association.rb
activefedora-aggregation-0.2.0 lib/active_fedora/aggregation/association.rb