Sha256: 53b1914cb596bcb74a6a8271e552dde0b74407b6c69afd03ea86cd7a3abb5c1b

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

module ActiveFedora
  # Helps Rubydora create datastreams of the type defined by the ActiveFedora::Base#datastream_class_for_name
  class UnsavedDigitalObject 
    attr_accessor :original_class, :ownerId, :datastreams, :label, :namespace
    
    def initialize(original_class, namespace, pid=nil)
      @pid = pid
      self.original_class = original_class
      self.namespace = namespace
      self.datastreams = {}
    end

    def pid
      @pid || '__DO_NOT_USE__'
    end


    # Set the pid.  This method is only avaialable before the object has been persisted in fedora.
    def pid=pid
      @pid = pid
    end

    def new?
      true
    end

    ### Change this into a real digital object
    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

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



  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active-fedora-4.5.0 lib/active_fedora/unsaved_digital_object.rb
active-fedora-4.4.1 lib/active_fedora/unsaved_digital_object.rb