Sha256: 47acf768c82d354ba993fd9d777a82d6bf86d81de745b74f01ded5d7760de412

Contents?: true

Size: 1.5 KB

Versions: 10

Compression:

Stored size: 1.5 KB

Contents

module ActiveFedora
  module Associations
    class DirectlyContainsAssociation < ContainsAssociation #:nodoc:

      def insert_record(record, force = true, validate = true)
        container.save!
        if force
          record.save!
        else
          record.save(validate: validate)
        end
      end

      def find_target
        query_node = if container_predicate = options[:has_member_relation]
           owner
        else
          container_predicate = ::RDF::Vocab::LDP.contains
          container
        end

        uris = query_node.resource.query(predicate: container_predicate).map { |r| r.object.to_s }

        uris.map { |object_uri| klass.find(klass.uri_to_id(object_uri)) }
      end

      def container
        @container ||= begin
          DirectContainer.find_or_initialize(ActiveFedora::Base.uri_to_id(uri)).tap do |container|
            container.parent = @owner
            container.has_member_relation = Array(options[:has_member_relation])
            container.is_member_of_relation = Array(options[:is_member_of_relation])
          end
        end
      end

      protected

        def initialize_attributes(record) #:nodoc:
          record.uri = ActiveFedora::Base.id_to_uri(container.mint_id)
          set_inverse_instance(record)
        end

      private

        def delete_records(records, method)
          if method == :destroy
            records.each { |r| r.destroy }
          else
            records.each { |r| r.delete }
          end
        end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
active-fedora-9.5.0 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.4.3 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.4.2 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.4.1 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.4.0 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.3.0 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.2.1 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.2.0 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.2.0.rc2 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.2.0.rc1 lib/active_fedora/associations/directly_contains_association.rb