module ActiveFedora::Persistence
def _create_record(_options = {})
def _create_record(_options = {}) assign_rdf_subject serialize_attached_files @ldp_source = @ldp_source.create assign_uri_to_contained_resources save_contained_resources refresh end
def _raise_record_not_destroyed
def _raise_record_not_destroyed @_association_destroy_exception ||= nil raise @_association_destroy_exception || RecordNotDestroyed.new("Failed to destroy the record", self) ensure @_association_destroy_exception = nil end
def _update_record(_options = {})
def _update_record(_options = {}) serialize_attached_files execute_sparql_update save_contained_resources refresh end
def assign_id
def assign_id end
def assign_rdf_subject
and assign_id can mint an id for the object, then assign it to the resource.
This is only used when creating a new record. If the object doesn't have an id
def assign_rdf_subject @ldp_source = if !id && new_id = assign_id LdpResource.new(ActiveFedora.fedora.connection, self.class.id_to_uri(new_id), @resource) else LdpResource.new(ActiveFedora.fedora.connection, @ldp_source.subject, @resource, base_path_for_resource) end end
def assign_uri_to_contained_resources
def assign_uri_to_contained_resources contained_resources.each do |name, source| source.uri = "#{uri}/#{name}" end end
def base_path_for_resource
def base_path_for_resource @base_path ||= ActiveFedora.fedora.host + default_base_path_for_resource end
def base_path_for_resource=(path)
def base_path_for_resource=(path) @base_path = path end
def contained_rdf_sources
def contained_rdf_sources @contained_rdf_sources ||= AssociationHash.new(self, self.class.contained_rdf_source_reflections) end
def contained_resources
def contained_resources @contained_resources ||= attached_files.merge(contained_rdf_sources) end
def create_or_update(*args)
def create_or_update(*args) raise ReadOnlyRecord if readonly? result = new_record? ? _create_record(*args) : _update_record(*args) result != false end
def default_base_path_for_resource
def default_base_path_for_resource init_root_path if has_uri_prefix? root_resource_path end
def delete(opts = {})
(**opts)
-
:eradicate
(Boolean
) -- if passed in, eradicate the tombstone from Fedora
Parameters:
-
opts
(Hash
) --
def delete(opts = {}) return self if new_record? @destroyed = true id = self.id ## cache so it's still available after delete # Clear out the ETag @ldp_source = build_ldp_resource(id) begin @ldp_source.delete rescue Ldp::NotFound raise ObjectNotFoundError, "Unable to find #{id} in the repository" end ActiveFedora::SolrService.delete(id) if ActiveFedora.enable_solr_updates? self.class.eradicate(id) if opts[:eradicate] freeze end
def destroy(*opts)
(**opts)
-
:eradicate
(Boolean
) -- if passed in, eradicate the tombstone from Fedora
Parameters:
-
opts
(Hash
) --
def destroy(*opts) raise ReadOnlyRecord if readonly? delete(*opts) end
def destroy!
and #destroy! raises ActiveFedora::RecordNotDestroyed.
before_destroy callback throws +:abort+ the action is cancelled
There's a series of callbacks associated with #destroy!. If the
that no changes should be made (since they can't be persisted).
Deletes the record in the database and freezes this instance to reflect
def destroy! destroy || _raise_record_not_destroyed end
def destroyed?
def destroyed? @destroyed end
def eradicate
def eradicate self.class.eradicate(id) end
def execute_sparql_update
def execute_sparql_update change_set = ChangeSet.new(self, resource, changed_attributes.keys) return true if change_set.empty? ActiveFedora.fedora.ldp_resource_service.update(change_set, self.class, id) end
def init_root_path
def init_root_path path = root_resource_path.gsub(/^\//, "") ActiveFedora.fedora.connection.head(path) rescue Ldp::NotFound ActiveFedora.fedora.connection.put(path, "") end
def new_record?
def new_record? @ldp_source.new? rescue Ldp::Gone false end
def persisted?
def persisted? !(destroyed? || new_record?) end
def refresh
def refresh @ldp_source = build_ldp_resource(id) @resource = nil end
def save(*options)
-
(Boolean)
- true if save was successful, otherwise false
Options Hash:
(**options)
-
:update_index
(Boolean
) -- set false to skip indexing
Parameters:
-
options
(Hash
) --
def save(*options) create_or_update(*options) end
def save!(*args)
def save!(*args) create_or_update(*args) end
def save_contained_resources
def save_contained_resources contained_resources.changed.each do |_, resource| resource.save end end
def update(attributes)
def update(attributes) assign_attributes(attributes) save end