Sha256: a49254c1cb9978c08497d30fb24cf23a2f7c22ebf2dbe0c35be8e98e98d90707
Contents?: true
Size: 1.26 KB
Versions: 22
Compression:
Stored size: 1.26 KB
Contents
module ActiveFedora class FixtureLoader attr_accessor :path def initialize(path) self.path = path end def filename_for_pid(pid) File.join(path, "#{pid.gsub(":","_")}.foxml.xml") end def self.delete(pid) begin ActiveFedora::Base.find(pid, cast: true).delete 1 rescue ActiveFedora::ObjectNotFoundError ActiveFedora::Base.logger.debug "The object #{pid} has already been deleted (or was never created)." if ActiveFedora::Base.logger 0 rescue Errno::ECONNREFUSED => e ActiveFedora::Base.logger.debug "Can't connect to Fedora! Are you sure jetty is running?" if ActiveFedora::Base.logger 0 end end def reload(pid) self.class.delete(pid) import_and_index(pid) end def import_and_index(pid) body = self.class.import_to_fedora(filename_for_pid(pid), pid) self.class.index(pid) body end def self.index(pid) ActiveFedora::Base.find(pid).update_index end def self.import_to_fedora(filename, pid='0') file = File.new(filename, "r") result = ActiveFedora::Base.connection_for_pid(pid).ingest(:file=>file.read) raise "Failed to ingest the fixture." unless result result.body end end end
Version data entries
22 entries across 22 versions & 1 rubygems