Class: ActiveFedora::UnsavedDigitalObject

Inherits:
Object
  • Object
show all
Includes:
DigitalObject::DatastreamBootstrap
Defined in:
lib/active_fedora/unsaved_digital_object.rb

Overview

Helps Rubydora create datastreams of the type defined by the ActiveFedora::Base#datastream_class_for_name

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DigitalObject::DatastreamBootstrap

#datastream_object_for

Constructor Details

#initialize(original_class, namespace, pid = nil) ⇒ UnsavedDigitalObject

Returns a new instance of UnsavedDigitalObject.



7
8
9
10
11
12
# File 'lib/active_fedora/unsaved_digital_object.rb', line 7

def initialize(original_class, namespace, pid=nil)
  @pid = pid
  self.original_class = original_class
  self.namespace = namespace
  self.datastreams = {}
end

Instance Attribute Details

#datastreamsObject

Returns the value of attribute datastreams.



5
6
7
# File 'lib/active_fedora/unsaved_digital_object.rb', line 5

def datastreams
  @datastreams
end

#labelObject

Returns the value of attribute label.



5
6
7
# File 'lib/active_fedora/unsaved_digital_object.rb', line 5

def label
  @label
end

#namespaceObject

Returns the value of attribute namespace.



5
6
7
# File 'lib/active_fedora/unsaved_digital_object.rb', line 5

def namespace
  @namespace
end

#original_classObject

Returns the value of attribute original_class.



5
6
7
# File 'lib/active_fedora/unsaved_digital_object.rb', line 5

def original_class
  @original_class
end

#ownerIdObject

Returns the value of attribute ownerId.



5
6
7
# File 'lib/active_fedora/unsaved_digital_object.rb', line 5

def ownerId
  @ownerId
end

Instance Method Details

#assign_pidObject



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

def assign_pid
    return @pid if @pid
    self.original_class.assign_pid(self)
end

#new?Boolean

Returns:

  • (Boolean)


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

def new?
  true
end

#pidObject



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

def pid
  @pid || '__DO_NOT_USE__'
end

#pid=(pid) ⇒ Object

Set the pid. This method is only avaialable before the object has been persisted in fedora.



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

def pid=pid
  @pid = pid
end

#saveObject

Change this into a real digital object



29
30
31
32
33
34
35
36
37
38
# File 'lib/active_fedora/unsaved_digital_object.rb', line 29

def save
  obj = DigitalObject.find_or_initialize(self.original_class, assign_pid)
  self.datastreams.each do |k, v|
    v.digital_object = obj
    obj.datastreams[k] = v
  end
  obj.ownerId = ownerId if ownerId
  obj.label = label if label
  obj
end