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

Constant Summary

PLACEHOLDER =
nil

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



9
10
11
12
13
14
# File 'lib/active_fedora/unsaved_digital_object.rb', line 9

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

#stateObject

Returns the value of attribute state



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

def state
  @state
end

Instance Method Details

#assign_pidObject



48
49
50
51
# File 'lib/active_fedora/unsaved_digital_object.rb', line 48

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

#deleteObject



53
54
55
# File 'lib/active_fedora/unsaved_digital_object.rb', line 53

def delete
  #nop
end

#new_record?Boolean Also known as: new?

Returns:

  • (Boolean)


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

def new_record?
  true
end

#pidObject



16
17
18
# File 'lib/active_fedora/unsaved_digital_object.rb', line 16

def pid
  @pid || PLACEHOLDER
end

#pid=(pid) ⇒ Object

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



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

def pid=pid
  @pid = pid
end

#saveObject

Change this into a real digital object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_fedora/unsaved_digital_object.rb', line 36

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.state = state if state
  obj
end

#uriObject



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

def uri
  "unsaved:#{pid}"
end