Class: ActiveFedora::Associations::DirectlyContainsAssociation

Inherits:
ContainsAssociation show all
Defined in:
lib/active_fedora/associations/directly_contains_association.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from CollectionAssociation

#proxy

Attributes inherited from Association

#inversed, #owner, #reflection, #target

Instance Method Summary collapse

Methods inherited from ContainsAssociation

#include?, #reader

Methods inherited from CollectionAssociation

#add_to_target, #any?, #build, #concat, #concat_records, #count, #create, #create!, #delete, #delete_all, #destroy, #destroy_all, #empty?, #find, #first, #ids_reader, #ids_writer, #include?, #last, #load_from_solr, #load_target, #null_scope?, #reader, #replace, #reset, #scope, #select, #size, #target=, #to_ary, #writer

Methods inherited from Association

#association_scope, #initialize, #load_target, #loaded!, #loaded?, #reload, #reset, #reset_scope, #scope, #set_inverse_instance, #stale_target?, #target_scope

Constructor Details

This class inherits a constructor from ActiveFedora::Associations::Association

Instance Method Details

#containerObject



22
23
24
25
26
27
28
29
30
# File 'lib/active_fedora/associations/directly_contains_association.rb', line 22

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

#find_targetObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/active_fedora/associations/directly_contains_association.rb', line 9

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

#insert_record(record, force = true, validate = true) ⇒ Object



4
5
6
7
# File 'lib/active_fedora/associations/directly_contains_association.rb', line 4

def insert_record(record, force = true, validate = true)
  container.save!
  super
end