Module: ActiveFedora::Persistence

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

Overview

Active Fedora Persistence

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#delete(opts = {}) ⇒ 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



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

def delete(opts = {})
  return self if new_record?

  @destroyed = true
  reflections.each_pair do |name, reflection|
    if reflection.macro == :has_many
      association(name.to_sym).delete_all
    end
  end

  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 ENABLE_SOLR_UPDATES
  if opts[:eradicate]
    self.class.eradicate(id)
  end
  freeze
end

#destroy(*args) ⇒ Object

Raises:



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

def destroy(*args)
  raise ReadOnlyRecord if readonly?
  delete(*args)
end

#destroyed?Boolean

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

Returns:

  • (Boolean)


15
16
17
# File 'lib/active_fedora/persistence.rb', line 15

def destroyed?
  @destroyed
end

#eradicateObject



76
77
78
# File 'lib/active_fedora/persistence.rb', line 76

def eradicate
  self.class.eradicate(self.id)
end

#new_record?Boolean

Returns:

  • (Boolean)


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

def new_record?
  @ldp_source.new?
end

#persisted?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/active_fedora/persistence.rb', line 10

def persisted?
  !(destroyed? || new_record?)
end

#save(*args) ⇒ 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)

Returns:

  • (Boolean)

    true if save was successful, otherwise false



26
27
28
# File 'lib/active_fedora/persistence.rb', line 26

def save(*args)
  create_or_update(*args)
end

#save!(*args) ⇒ Object



30
31
32
# File 'lib/active_fedora/persistence.rb', line 30

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



35
36
37
38
# File 'lib/active_fedora/persistence.rb', line 35

def update(attributes)
  self.attributes=attributes
  save
end