Module: ActiveFedora::Persistence
- Extended by:
- ActiveSupport::Concern, Deprecation
- Included in:
- Base
- Defined in:
- lib/active_fedora/persistence.rb
Overview
Active Fedora Persistence
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#assert_content_model ⇒ Object
This can be overriden to assert a different model It’s normally called once in the lifecycle, by #create#.
-
#delete ⇒ Object
Deletes a Base object, also deletes the info indexed in Solr, and the underlying inner_object.
- #destroy ⇒ Object
-
#destroyed? ⇒ Boolean
Returns true if this object has been destroyed, otherwise returns false.
- #new? ⇒ Boolean
-
#new_object? ⇒ Boolean
Has this object been saved?.
-
#new_record? ⇒ Boolean
Required by associations.
- #persisted? ⇒ Boolean
-
#refresh ⇒ Object
Refreshes the object’s info from Fedora Note: Currently just registers any new datastreams that have appeared in fedora.
-
#save ⇒ Object
Saves a Base object, and any dirty datastreams, then updates the Solr index for this object.
- #save! ⇒ Object
-
#update(attributes) ⇒ Object
(also: #update_attributes)
Pushes the object and all of its new or dirty datastreams into Fedora.
Instance Method Details
#assert_content_model ⇒ Object
This can be overriden to assert a different model It’s normally called once in the lifecycle, by #create#
48 49 50 |
# File 'lib/active_fedora/persistence.rb', line 48 def assert_content_model add_relationship(:has_model, self.class.to_class_uri) end |
#delete ⇒ Object
Deletes a Base object, also deletes the info indexed in Solr, and the underlying inner_object. If this object is held in any relationships (ie inbound relationships outside of this object it will remove it from those items rels-ext as well
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/active_fedora/persistence.rb', line 69 def delete reflections.each_pair do |name, reflection| if reflection.macro == :has_many association(name).delete_all end end pid = self.pid ## cache so it's still available after delete begin @inner_object.delete rescue RestClient::ResourceNotFound =>e raise ObjectNotFoundError, "Unable to find #{pid} in the repository" end if ENABLE_SOLR_UPDATES solr = ActiveFedora::SolrService.instance.conn solr.delete_by_id(pid, params: {'softCommit' => true}) end @destroyed = true freeze end |
#destroy ⇒ Object
90 91 92 |
# File 'lib/active_fedora/persistence.rb', line 90 def destroy delete end |
#destroyed? ⇒ Boolean
Returns true if this object has been destroyed, otherwise returns false.
31 32 33 |
# File 'lib/active_fedora/persistence.rb', line 31 def destroyed? @destroyed end |
#new? ⇒ Boolean
9 10 11 |
# File 'lib/active_fedora/persistence.rb', line 9 def new? new_record? end |
#new_object? ⇒ Boolean
Has this object been saved?
15 16 17 |
# File 'lib/active_fedora/persistence.rb', line 15 def new_object? new_record? end |
#new_record? ⇒ Boolean
Required by associations
22 23 24 |
# File 'lib/active_fedora/persistence.rb', line 22 def new_record? inner_object.new_record? end |
#persisted? ⇒ Boolean
26 27 28 |
# File 'lib/active_fedora/persistence.rb', line 26 def persisted? !(new_record? || destroyed?) end |
#refresh ⇒ Object
Refreshes the object’s info from Fedora Note: Currently just registers any new datastreams that have appeared in fedora
62 63 64 |
# File 'lib/active_fedora/persistence.rb', line 62 def refresh # inner_object.load_attributes_from_fedora end |
#save ⇒ Object
Saves a Base object, and any dirty datastreams, then updates the Solr index for this object.
37 38 39 40 |
# File 'lib/active_fedora/persistence.rb', line 37 def save(*) # If it's a new object, set the conformsTo relationship for Fedora CMA new_record? ? create : update_record end |
#save! ⇒ Object
42 43 44 |
# File 'lib/active_fedora/persistence.rb', line 42 def save!(*) save end |
#update(attributes) ⇒ Object Also known as: update_attributes
Pushes the object and all of its new or dirty datastreams into Fedora
53 54 55 56 |
# File 'lib/active_fedora/persistence.rb', line 53 def update(attributes) self.attributes=attributes save end |