Class: ActiveFedora::Associations::DirectlyContainsAssociation
- Inherits:
-
ContainsAssociation
- Object
- Association
- CollectionAssociation
- ContainsAssociation
- ActiveFedora::Associations::DirectlyContainsAssociation
- Defined in:
- lib/active_fedora/associations/directly_contains_association.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from CollectionAssociation
Attributes inherited from Association
#inversed, #owner, #reflection, #target
Instance Method Summary collapse
- #container ⇒ Object
- #find_target ⇒ Object
- #insert_record(record, force = true, validate = true) ⇒ Object
Methods inherited from ContainsAssociation
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
#container ⇒ Object
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([:has_member_relation]) container.is_member_of_relation = Array([:is_member_of_relation]) end end end |
#find_target ⇒ Object
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 = [: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 |