Class: ActiveFedora::Associations::RDF

Inherits:
SingularAssociation show all
Defined in:
lib/active_fedora/associations/rdf.rb

Overview

:nodoc:

Direct Known Subclasses

SingularRDF

Instance Attribute Summary

Attributes inherited from Association

#inversed, #owner, #reflection, #target

Instance Method Summary collapse

Methods inherited from SingularAssociation

#build, #create, #create!, #writer

Methods inherited from Association

#association_scope, #initialize, #initialize_attributes, #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

#destroyObject



21
22
23
24
25
26
# File 'lib/active_fedora/associations/rdf.rb', line 21

def destroy
  filtered_results.each do |candidate|
    owner.resource.delete([owner.rdf_subject, reflection.predicate, candidate])
  end
  owner.resource.persist!
end

#readerObject



17
18
19
# File 'lib/active_fedora/associations/rdf.rb', line 17

def reader
  filtered_results.map { |val| ActiveFedora::Base.uri_to_id(val) }
end

#replace(values) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/active_fedora/associations/rdf.rb', line 4

def replace(values)
  ids = Array(values).reject(&:blank?)
  raise "can't modify frozen #{owner.class}" if owner.frozen?
  current_objects = filtered_results
  incoming_objects = ids.map { |id| ::RDF::URI(ActiveFedora::Base.id_to_uri(id)) }
  deletions = current_objects - incoming_objects
  additions = incoming_objects - current_objects
  deletions.each { |object| owner.resource.delete([owner.rdf_subject, reflection.predicate, object]) }
  additions.each { |object| owner.resource.insert([owner.rdf_subject, reflection.predicate, object]) }
  owner.resource.persist!
  owner.send(:attribute_will_change!, reflection.name)
end