Module: ActiveFedora::Persistence

Extended by:
ActiveSupport::Concern
Included in:
Base, FilePersistence
Defined in:
lib/active_fedora/persistence.rb

Overview

Active Fedora Persistence

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#base_path_for_resource=(path) ⇒ Object

Used when setting containment



91
92
93
# File 'lib/active_fedora/persistence.rb', line 91

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.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :eradicate (Boolean)

    if passed in, eradicate the tombstone from Fedora



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/active_fedora/persistence.rb', line 48

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

Parameters:

  • opts (Hash)

Options Hash (*opts):

  • :eradicate (Boolean)

    if passed in, eradicate the tombstone from Fedora

Raises:



70
71
72
73
# File 'lib/active_fedora/persistence.rb', line 70

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.



82
83
84
# File 'lib/active_fedora/persistence.rb', line 82

def destroy!
  destroy || _raise_record_not_destroyed
end

#destroyed?Boolean

Returns true if this object has been destroyed, otherwise returns false.

Returns:

  • (Boolean)


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

def destroyed?
  @destroyed
end

#eradicateObject



86
87
88
# File 'lib/active_fedora/persistence.rb', line 86

def eradicate
  self.class.eradicate(id)
end

#new_record?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
# File 'lib/active_fedora/persistence.rb', line 6

def new_record?
  @ldp_source.new?
rescue Ldp::Gone
  false
end

#persisted?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/active_fedora/persistence.rb', line 12

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.

Parameters:

  • options (Hash)

Options Hash (*options):

  • :update_index (Boolean) — default: true

    set false to skip indexing

Returns:

  • (Boolean)

    true if save was successful, otherwise false



28
29
30
# File 'lib/active_fedora/persistence.rb', line 28

def save(*options)
  create_or_update(*options)
end

#save!(*args) ⇒ Object



32
33
34
# File 'lib/active_fedora/persistence.rb', line 32

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



37
38
39
40
# File 'lib/active_fedora/persistence.rb', line 37

def update(attributes)
  assign_attributes(attributes)
  save
end