Module: ActiveFedora::Persistence
- Extended by:
- ActiveSupport::Autoload, ActiveSupport::Concern
- Included in:
- Base, FilePersistence
- Defined in:
- lib/active_fedora/persistence.rb,
lib/active_fedora/persistence/null_identifier_service.rb
Overview
Active Fedora Persistence
Defined Under Namespace
Modules: ClassMethods Classes: NullIdentifierService
Instance Method Summary collapse
-
#base_path_for_resource=(path) ⇒ Object
Used when setting containment.
-
#delete(opts = {}) ⇒ Object
Deletes an object from Fedora and deletes the indexed record from Solr.
-
#destroy(*opts) ⇒ Object
Delete the object from Fedora and Solr.
-
#destroy! ⇒ Object
Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can’t be persisted).
-
#destroyed? ⇒ Boolean
Returns true if this object has been destroyed, otherwise returns false.
- #eradicate ⇒ Object
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
-
#save(*options) ⇒ Boolean
Saves a Base object, and any dirty attached files, then updates the Solr index for this object, unless option :update_index=>false is present.
- #save!(*args) ⇒ Object
-
#update(attributes) ⇒ Object
(also: #update_attributes)
Pushes the object and all of its new or dirty attached files into Fedora.
-
#update!(attributes) ⇒ Object
(also: #update_attributes!)
Updates its receiver just like #update but calls #save! instead of
save
, so an exception is raised if the record is invalid and saving will fail.
Instance Method Details
#base_path_for_resource=(path) ⇒ Object
Used when setting containment
111 112 113 |
# File 'lib/active_fedora/persistence.rb', line 111 def base_path_for_resource=(path) @base_path = path end |
#delete(opts = {}) ⇒ Object
Deletes an object from Fedora and deletes the indexed record from Solr. Delete does not run any callbacks, so consider using destroy instead.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/active_fedora/persistence.rb', line 68 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 |
#destroy(*opts) ⇒ Object
Delete the object from Fedora and Solr. Run any before/after/around callbacks for destroy
90 91 92 93 |
# File 'lib/active_fedora/persistence.rb', line 90 def destroy(*opts) raise ReadOnlyRecord if readonly? delete(*opts) end |
#destroy! ⇒ Object
Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can’t be persisted).
There’s a series of callbacks associated with #destroy!. If the before_destroy
callback throws :abort
the action is cancelled and #destroy! raises ActiveFedora::RecordNotDestroyed. See ActiveFedora::Callbacks for further details.
102 103 104 |
# File 'lib/active_fedora/persistence.rb', line 102 def destroy! destroy || _raise_record_not_destroyed end |
#destroyed? ⇒ Boolean
Returns true if this object has been destroyed, otherwise returns false.
28 29 30 |
# File 'lib/active_fedora/persistence.rb', line 28 def destroyed? @destroyed end |
#eradicate ⇒ Object
106 107 108 |
# File 'lib/active_fedora/persistence.rb', line 106 def eradicate self.class.eradicate(id) end |
#new_record? ⇒ Boolean
13 14 15 16 17 18 19 20 21 |
# File 'lib/active_fedora/persistence.rb', line 13 def new_record? return true if @ldp_source.subject.nil? @ldp_source.get false rescue Ldp::Gone false rescue Ldp::NotFound true end |
#persisted? ⇒ Boolean
23 24 25 |
# File 'lib/active_fedora/persistence.rb', line 23 def persisted? !(destroyed? || new_record?) end |
#save(*options) ⇒ Boolean
Saves a Base object, and any dirty attached files, then updates the Solr index for this object, unless option :update_index=>false is present. Indexing is also controlled by the ‘create_needs_index?’ and ‘update_needs_index?’ methods.
39 40 41 |
# File 'lib/active_fedora/persistence.rb', line 39 def save(*) create_or_update(*) end |
#save!(*args) ⇒ Object
43 44 45 |
# File 'lib/active_fedora/persistence.rb', line 43 def save!(*args) create_or_update(*args) end |
#update(attributes) ⇒ Object Also known as: update_attributes
Pushes the object and all of its new or dirty attached files into Fedora
48 49 50 51 |
# File 'lib/active_fedora/persistence.rb', line 48 def update(attributes) assign_attributes(attributes) save end |
#update!(attributes) ⇒ Object Also known as: update_attributes!
Updates its receiver just like #update but calls #save! instead of save
, so an exception is raised if the record is invalid and saving will fail.
57 58 59 60 |
# File 'lib/active_fedora/persistence.rb', line 57 def update!(attributes) assign_attributes(attributes) save! end |