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

Instance Method Details

#assert_content_modelObject

This can be overriden to assert a different model It’s normally called once in the lifecycle, by #create#



50
51
52
# File 'lib/active_fedora/persistence.rb', line 50

def assert_content_model
  add_relationship(:has_model, self.class.to_class_uri)
end

#deleteObject

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



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/active_fedora/persistence.rb', line 71

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

#destroyObject



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

def destroy
  delete
end

#destroyed?Boolean

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

Returns:

  • (Boolean)


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

def destroyed?
  @destroyed
end

#new?Boolean

Returns:

  • (Boolean)


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

def new?
  new_record?
end

#new_object?Boolean

Has this object been saved?

Returns:

  • (Boolean)


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

def new_object?
  new_record?
end

#new_record?Boolean

Required by associations

Returns:

  • (Boolean)


20
21
22
# File 'lib/active_fedora/persistence.rb', line 20

def new_record?
  inner_object.new_record?
end

#persisted?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/active_fedora/persistence.rb', line 24

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

#refreshObject

Refreshes the object’s info from Fedora Note: Currently just registers any new datastreams that have appeared in fedora



64
65
66
# File 'lib/active_fedora/persistence.rb', line 64

def refresh
#      inner_object.load_attributes_from_fedora
end

#save(options = {}) ⇒ Boolean

Saves a Base object, and any dirty datastreams, 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) (defaults to: {})

Options Hash (options):

  • :update_index (Boolean) — default: true

    set false to skip indexing

Returns:

  • (Boolean)

    true if save was successful, otherwise false



40
41
42
# File 'lib/active_fedora/persistence.rb', line 40

def save(options={})
  new_record? ? create(options) : update_record(options)
end

#save!(options = {}) ⇒ Object



44
45
46
# File 'lib/active_fedora/persistence.rb', line 44

def save!(options={})
  save(options)
end

#update(attributes) ⇒ Object Also known as: update_attributes

Pushes the object and all of its new or dirty datastreams into Fedora



55
56
57
58
# File 'lib/active_fedora/persistence.rb', line 55

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