Sha256: 9de815efeb5113c41d15b610ca39403a685a39811ab934e9fed1d6c81e72730f

Contents?: true

Size: 1.55 KB

Versions: 20

Compression:

Stored size: 1.55 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(&:destroy)
          else
            records.each(&:delete)
          end
        end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
active-fedora-9.7.3 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.7.2 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.12.0 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.11.0 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.10.4 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.10.3 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.10.2 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.10.1 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.10.0 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.10.0.pre2 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.10.0.pre1 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.9.1 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.9.0 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.8.2 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.8.1 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.8.0 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.7.1 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.7.0 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.6.2 lib/active_fedora/associations/directly_contains_association.rb
active-fedora-9.6.1 lib/active_fedora/associations/directly_contains_association.rb